ãã㯠Chromium Browserã¢ããã³ãã«ã¬ã³ãã¼ã®15æ¥ç®ã®è¨äºã§ãã
ãã®è¨äºã§ã¯æå±ããé»åæ
å ±å·¥å¦ç§ã®å®é¨ã§Chromiumã«ãæå®ãããã¼ã¯ã¼ããå«ãç¹å®ã®æ¤ç´¢å±¥æ´ã®ã¿é表示ã«ãããã¨ããæ©è½ãåæã«å®è£
ããæã®ä½é¨ãã¤ãã¤ãæ¸ãã¦è¡ãããã¨æãã¾ãã
å¦ç§ã®å
輩ã§ç¾å¨Blink-Workerãã¼ã ã«ããã£ãããamiq11ãããå¨å¦ä¸ã«ãã®å®é¨ã®TAãããã¦ãããã¨ããã£ã¦å£°ãããã¦ããã ãã¾ããã
ããã®æ¹ã
ã«ããã¨ã¦ãç´ æµãªè¨äºã°ããã並ã¶ä¸ã§æ縮ã§ããããã¡ãã£ã¨åå¼·ãã¦ãChromiumã®ã½ã¼ã¹ã³ã¼ããã¨ããããèªãã§ã¿ã¦ãä½ãã¡ãã£ã¨ããæ©è½ãå ãã¦ã¿ãããæ¹é ãããããª
ããããªäººã
ã®åèã«ãªãã°å¬ããã§ãâ¦ï¼
ãªãã§å¤§å¦ã®å®é¨ã§Chromiumï¼
æ±å¤§å·¥å¦é¨é»æ°ç³»3å¹´çã¯3ã6åã®ãã¼ãã®å®é¨ãè¡ããã¨ãå¿
ä¿®ã¨ãªã£ã¦ãããç§ã¯ä»å¦æãä»ã®äºã¤ã®å®é¨ã¨ä½µãã¦ç°æµ¦å¥äºéå
çã«ããã大è¦æ¨¡ã½ããã¦ã§ã¢ãææ¢ããå®é¨ã履修ãã¾ããã
ãã®å®é¨ã¯ãæ¼ç¿ã¬ãã«ã®å°ããªããã°ã©ã ãä½ãããã¨ãã¨ããå®ç¨è¦æ¨¡ã®ããã°ã©ã ãä½ãããã¨ãã®ã®ã£ãããåãã (ããã®ç¥èã¨çµé¨ãå¾ã)ãã¨ãç®çã«ã1ãæ°ç¾ä¸è¡ã®ãªã¼ãã³ã½ã¼ã¹ã½ããã¦ã§ã¢ãã½ã¼ã¹ãããã«ããæ°ããæ©è½ãå ããããã¾ãã
Chromiumã®ä»ã«Firefoxã®JavaScriptã¨ã³ã¸ã³ãSpiderMonkeyãæè¿ãã®ãªãããªèªåè£å®ãªã©ã§äººæ°ãªfish shellãé¡æã«ããçãããã
å®éã«æ¬å®¶ã«PRãåºãã¦å¤æ´ããã¼ã¸ãããããã¦ãã¾ãã
å®é¨ã§è¿½å ããæ©è½
ä»åç§ã®çãå®è£
ããã®ã¯ããChromiumã®è¨å®ç»é¢ã§é表示ãã¼ã¯ã¼ããè¨å®ããã¨ãChromiumä¸é¨ã®æ¤ç´¢ããã¯ã¹ã®èªåè£å®åè£ãããã®ãã¼ã¯ã¼ããå«ãéå»ã®æ¤ç´¢å±¥æ´ãé¤ããã¨ãããã®ã§ãã
Chromeä¸é¨ã®æ¤ç´¢ããã¯ã¹ã®æ£å¼å称ã¯ãOmniboxãã¨ãããã¦ã¼ã¶ã¼ã®å
¥åã«å¾ã£ã¦ããéå»ã«æ¤ç´¢ããæ¤ç´¢ã¯ã¨ãªããéå»ã«é²è¦§ãããã¼ã¸ã®URLããGoogleæ¤ç´¢ã§äººæ°ã®æ¤ç´¢ããªã©æ§ã
ãªã¿ã¤ãã®èªåè£å®åè£ããµã¸ã§ã¹ããã¦ããã¦ãã¾ãã
ã¡ãªã¿ã«safariã ã¨ãããªæããChromeã§ã¯æ§ã ãªã¿ã¤ãã®èªåè£å®åè£ã並ã¹ããã¦è¡¨ç¤ºãããã®ã«å¯¾ãã safariã¯ããããã®èªåè£å®åè£ã®ã¿ã¤ãå¥ã«ã»ã¯ã·ã§ã³ãåãã¦ããã®ããããã¾ããã
ä»åã¯ã©ãåå¿è
ãChromiumã®ã½ã¼ã¹ãããã«ããã¦æ°ç¾ä¸è¡ããChromiumã½ã¼ã¹ã³ã¼ãããå¤æ´ãããç®æãè¦ã¤ãã
æ©è½ã追å ãã¦ããã®ããæ¸ãããã¨æãã¾ãã
ãã®å®é¨ã§ã¯ãå®é¨ã¬ãã¼ãã®ä»£ããã«ããã°è¨äºãæåºå¯è½ã¨ããã«ã¼ã«ãããããã
ãããã詳細ãªå
容(ã¨ãããæªæ¦è¦éã®æ§å)ãç¥ãããå¥ç¹ãªæ¹ãããã£ãããã°ä¸ã«ããããã®ã¹ãããã¨å¯¾å¿ãããæåºããè¨äºã®ä¸è¦§ãè²¼ã£ãã®ã§ã®ããã¦ã¿ã¦ãã ãã(ï¾â½ï¾*)
å¤æ´ããå 容 | ããã°è¨äº |
---|---|
ãã«ããã | 大規模ソフトウェア(Chromium)を手探る 導入・ビルド編 - あさりさんの作業ログ |
ã½ã¼ã¹ã³ã¼ãã¨ããã¥ã¡ã³ããææ¢ã | 大規模ソフトウェアを手探る Chromeのソースコードとドキュメントをひたすら漁る - あさりさんの作業ログ |
æ¤ç´¢ããã¯ã¹ã®ãã¼ã¿ã®æµãã追ããèªåè£å®åè£ã«ãã¼ã¯ã¼ããã£ã«ã¿ã¼ãããã | 大規模ソフトウェアを手探る 検索ボックスにおける自動補完・サジェスチョンのデータの流れを追う - あさりさんの作業ログ |
user profileã«æ°ããè¨å®é ç®ã追å | 大規模ソフトウェア(Chromium)を手探る user profileに設定を追加する - あさりさんの作業ログ |
è¨å®ç»é¢ã«é表示ãã¼ã¯ã¼ããæ°ãã追å ããããã®æ°ããªWebUIãã¤ãã | 大規模ソフトウェア(Chromium)を手探る - 設定画面(settings)を手探る1 - - elechoのぶろぐ |
å ¥åããæ å ±ãuser profileã«å¼ã渡ãããã®call backãã³ãã©ãå®è£ ãã | 大規模ソフトウェア(Chromium)を手探る callbackハンドラを追加する・全体の感想 - あさりさんの作業ログ |
ã½ã¼ã¹ã³ã¼ãã(æåéã)ææ¢ã
å®è£ ããæ¹æ³ã¨ãã¦ãå½åã¯ä»¥ä¸ã®äºã¤ã®ã¢ã¤ãã£ã¢ãèãã¾ããã
- å ¥åã«å¾ã£ã¦æ¤ç´¢ããã¯ã¹ã®èªåè£å®æ å ±ãæ´æ°ãã¦ããã¢ã¸ã¥ã¼ã«ä¸ã§ãç¹å®ã®åèªãå«ã¾ããæ¤ç´¢å±¥æ´ã¯èªåè£å®åè£ããå¼¾ãããã«ããã
- ç¹å®ã®åèªãå«ã¾ããæ¤ç´¢ã¯ã¼ãã¯ããããæ¤ç´¢å±¥æ´DBã«ä¿åãããªãããã«ããã
ãããããã¼ã¿ã«ããæ®ããªãã®ã£ã¦ã©ããªãã ï¼ã¨ãããã¨ã§ãæ¹é1ã§å®è£ é²ãã¦è¡ããã¨ã«ãã¾ããã
Design Docãæ¢ãã¦ã¿ã
Chromium Browseråæ¥ã®è¨äºã§ç´¹ä»ããã ãã¦ããããã«ã
Chromiumã«ã¯å¼·åãªã³ã¼ããµã¼ããã¼ã¸ãããã¾ãããã åå°åã®ãªãåå¿è
ãæ°ç¾ä¸è¡ä»¥ä¸ã¨ãè¨ãããChromiumã®ã½ã¼ã¹ã³ã¼ãããããªãããã£ã½ããã¼ã¯ã¼ãã§ãµã¼ããã/ç®grepãããã¨ããã¨ã
æã¦ããªãå£ã«ã¶ã¤ããã¾ãã
ãã趣å³ã§ææ¢ã£ã¦ã¿ããï¼ã¨ããæ¹ãããã°ãã¾ãé¢é£ããDesign Docsãæ¤ç´¢ããèªåãããã£ã¦ã¿ããã¢ã¸ã¥ã¼ã«ã¯ã©ãããã½ã¼ã¹ã³ã¼ãã¯ã©ã®ãã£ã¬ã¯ããªã«ããããããããç¨åº¦ç®å¦ãã¤ãããã¨ããªã¹ã¹ã¡ãã¾ã(èªåã®æè¨ã§ã)ã
Chromium (Chrome Browser, Chrome OS)ã®éçºè
åãããã¥ã¡ã³ã (design doc) ã¯å
¬å¼ãã¼ã ãã¼ã¸ãThe Chromium Projectã®For Developers>Design Documentsããæ¤ç´¢ã§ãã¾ãã
ããã§Omniboxã§æ¤ç´¢ãããã¦ã¿ãã¨ãOmnibox: History Provider - The Chromium Projectsã¨ããããã¥ã¡ã³ãã«ä»¥ä¸ã®ãããªè¨è¿°ãããã®ã確èªã§ãã¾ãã
One of the autocomplete providers for the omnibox (the HistoryQuickProvider, HQP for short) serves up autocomplete candidates from the profile's history database. As the user starts typing into the omnibox, the HQP performs a search in its index of significant historical visits for the term or terms which have been typed.
HistoryProviderèªä½ã¯éå»ã®æ¤ç´¢å±¥æ´ããå ¥åæååã¨ããããã¦ãããªã¨ã³ããªãè¿ãã®ã§ãä»åã®ãã¦ã¼ã¶ã¼ã®éå»ã«å ¥åããæ¤ç´¢æååããOmniboxã«ä¾çµ¦ãã¦ãã訳ã§ã¯ãªãã®ã§ããã ä¸ã®è¨è¿°ããèªåè£å®åè£ã¯æ§ã ãªç¨®é¡ã®ãããã¤ãããã¦ã¼ã¶ã¼ã®æ¤ç´¢å±¥æ´DBããä¾çµ¦ããã¦ãããã¨ãã¦ã¼ã¶ã¼ã®å ¥åã«å¿ãã¦å ¥åæååã¨ãããããéå»ã®å±¥æ´ãè£å®åè£ã¨ãã¦ãµã¸ã§ã¹ããã¦ããã®ãæ¨æ¸¬ã§ãã¾ãã
ã¾ãChromeã®User Experimenté¢é£ã®ããã¥ã¡ã³ããOmnibox - The Chromium Projectsãã¿ãã¨ããããããã¦ã¼ã¶ã¼ãæ¤ç´¢ã®éã«å®éã«å ¥åããæååã«åºã¥ããµã¸ã§ã¹ãã§ã³ãã¯Search Suggestã¨ããã¿ã¤ãã«åé¡ããã¦ããã¨ãããã¾ãã SearchProviderã¿ãããªååãã¤ãã¦ããâ¦â¦â¦ãã£ããã§ããã ãããç®å¦ãã¤ãã¦ãã¾ããã
å®éã«ã³ã¼ããã¡ãã£ã¨ããã£ã¦ã¿ã
Chrome Code Searchã§SearchProviderã¯ã©ã¹ãã©ãã«ãããã¡ãã£ã¨èª¿ã¹ã¦ã¿ãã¨ã src/components/omnibox/browser/search_provider.cc ã§å®éã«SearchProviderã¯ã©ã¹ãå®éã«å®ç¾©ããã¦ãããã¨ããããã¾ãã
æåã¯åç´ã«ãã®SearchProviderã®ä¸ã§ãã¼ã¯ã¼ããã£ã«ã¿ã¼ããããã°ããã®ã§ã¯ï¼ï¼ã¨å®æã«èããã¨ããããããæååã¨ãµã¸ã§ã¹ãã§ã³ãä¸è´ããå ´åã¯èªåè£å®åè£ããé¤ããå®éã«ãµã¸ã§ã¹ãã§ã³ããæ¶ããã確èªãã¦ã¿ããã¨ã«ãã¾ããã
SearchProvider::ScoreHistoryResultsHelper(...) { SearchSuggestionParser::SuggestResults scored_results; if (base::EqualsASCII(history_suggestions.suggestion(), âhogehogeâ) == false){ scored_results.insert(insertion_position, history_suggestion); } return scored_result; }
çµæ : æ®éã«èªåè£å®ã«åºã¦ããwwwwww
ã©ãããåç´ã«Providerå´ã§ã¨ããããå¼¾ããã¨ããå®è£ ã ãã§ã¯ä¸ååã ã£ããããªã®ã§ã ã¡ããã¨èªåè£å®ã®ãã¼ã¿ãã©ãæµãã¦ãã¦ããã®ãããããã«ã§è¿½ã£ã¦ã¿ããã¨ã«ãã¾ããã
èªåè£å®ã®ãã¼ã¿ã®æµãã追ã£ã¦ã¿ã
å°éã«ãããã¯ãã¨ã©ã¼ã®ããã¯ãã¬ã¼ã¹çµæãã¿ãã¨ãOmniboxã®èªåè£å®åè£ã¯
- ã¾ãä¸å³ã®å³æå´ã«ããããããã®Providerãå ¥åã¨ããããããã¼ã¿ãprofileãªã©ããããããåã£ã¦ãã
- Controllerã¯ã©ã¹ãããããã¹ã¦ã®èªåè£å®åè£ãAutocomoleteMatchesã«ã¾ã¨ãã(ãã®çµæãå³ã®matches_)
- é¢é£åº¦çã«åºã¥ãã¦ãã®èªåè£å®åè£ãã½ã¼ããã(ãã®çµæãå³ã®autcocomplete_result_)
- ã½ã¼ããããçµæãæ°ããªèªåè£å®åè£ã¨ãã¦æ´æ°ããã
ã®æµãã§æä¾ããã¦ãããã¨ããããã¾ããã
次ã«ãä¸åä¸åãããã¤ãããèªåè£å®ãã¼ã¿ã渡ãã¦ããé¨åãã³ã¡ã³ãã¢ã¦ãããé ã®æªãæãã®ä½æ¥ããã¦SearchProviderã®åè£ãã確ãã«é¤ããã¯ãã®
é表示ãã¼ã¯ã¼ãèªåè£å®ãã©ãããæµãã¦ããã®ãæ¤è¨¼ãã¦ã¿ãã¨ãå®ã¯ShortcutProviderã¨ããã¯ã©ã¹ããå¼¾ããã¯ãã®ãã¼ã¿ãä¾çµ¦ããã¦ãããã¨ããããã¾ããã
Providerã®ä¸ã§ãä¸çªä¸ã«ç¤ºãããæå³ããããªShortcutProviderã¨ããProviderã¯ã©ã¹ãå½åã¯ãã¾ãã¡ããã¨ãã¼ã¯ãã¦ããªãã£ãã®ã§ããã ãã®ã¯ã©ã¹ã®ãããã¼ãã¡ã¤ã«ãè¦ã¦ã¿ãã¨ä»¥ä¸ã®è¨è¿°ãããã¾ãã
// Provider of recently autocompleted links. Provides autocomplete suggestions // from previously selected suggestions. The more often a user selects a // suggestion for a given search term the higher will be that suggestion's // ranking for future uses of that search term. class ShortcutsProvider : public AutocompleteProvider, public ShortcutsBackend::ShortcutsBackendObserver {...}
"Provider of recently autocompleted links. Provides autocomplete suggestions from previously selected suggestions. "
ã??????
ã¤ã¾ããããã¿ãã¨ãæè¿ãµã¸ã§ã¹ããããã¦ã¼ã¶ã¼ãå®éã«æ¤ç´¢ããåè£ã®ãã¼ã¿ãå¥ã®DBã«ä¿åãããããããã¼ã¿ãä¾çµ¦ãã¦ãããã¨ããããã¾ããã ããããã¨ä¾ãSearchProviderå´ã§ãããã¼ã¯ã¼ããå«ããã®ãèªåè£å®åè£ããé¤ãã¦ãããã¡ãã®Providerå´ãèªã¿è¾¼ãã§ããDBã«ãã§ã« é表示ãã¼ã¯ã¼ããå«ãã å±¥æ´ãæ®ããã¦ããã¨ããã¡ããããã¼ã¿ãä¾çµ¦ããã¦ãã¾ããã¨ããããã¾ãã
ããããã®åã
ã®Providerã«ãã£ã«ã¿ã¼ãããããããªå®è£
ã§ãããã£ãã®ããããã¾ããããèªåè£å®ã¨ãã¦éããããçµæã«å²ã¨éè¤ãå¤ããã¨ãããç¡é§ãå¤ãã®ã§ã¯ãªããï¼ã¨ããææãTAã®æ¹ã«ããã ããã¾ããã
ããã§ä»¥ä¸ã®ããã«ãå
¨ã¦ã®è£å®åè£ãã¾ã¨ãã¦éè¤ãé¤ããå¾ãé表示ãã¼ã¯ã¼ããå«ããªããã¯é表示ãã¼ã¯ã¼ãã¨ä¸è´ããèªåè£å®çµæã«ã¤ãã¦ã¯é¤å¤ããããã«å¤æ´ãå ãã¾ããã
å¾è¿°ããUser Profileã®æ
å ±ãèªã¿è¾¼ãã§é表示ãã¼ã¯ã¼ããè¨å®ããã¦ããå ´åã«ã¯SortAndCullWithKeyword()
é¢æ°ãå¼ã³ããã®SortAndCullWithKeyword()
ã¯é表示ãã¼ã¯ã¼ããå«ããã©ããfind()
ã§å¤å®ããã®ãããå¾ã«
SortAndCull()
ã¨ããåè£ã®ã½ã¼ããè¡ãé¢æ°ã«æ¸¡ãã¦ãã¾ãã
bool IsRemovableTypeFromMatch(AutocompleteMatchType::Type type) { return type == AutocompleteMatchType::HISTORY_TITLE || type == AutocompleteMatchType::HISTORY_BODY || type == AutocompleteMatchType::SEARCH_HISTORY || type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL; } } // namespace void AutocompleteResult::SortAndCullWithKeyword( const AutocompleteInput& input, TemplateURLService* template_url_service, const std::string& keyword) { std::vector<base::string16> restricted_keywords = TokenizesKeywordsStringToKeywordsVec(keyword); const base::string16& input_text = input.text(); matches_.erase( std::remove_if( matches_.begin(), matches_.end(), [&restricted_keywords, &input_text](const AutocompleteMatch& match) { bool removable = IsRemovableTypeFromMatch(match.type); if (removable) { base::string16 match_text = base::ToLowerASCII(match.contents); for (auto& restricted_keyword : restricted_keywords) { // Omniboxã®å ¥åæååã¨ä¸è´ããªããã¤è¡¨ç¤ºããããªããã¼ã¯ã¼ããå«ãæ¤ç´¢åè£ãé¤ãããã«æ¸ãæããã if (input_text != match_text && match_text.find(restricted_keyword) != base::string16::npos) { return true; } } } return false; }), matches_.end()); SortAndCull(input, template_url_service); }
IsRemovableTypeFromMatch()
ã¯èªåè£å®åè£ãã¦ã¼ã¶ã¼ã®éå»ã®æ¤ç´¢ã«åºã¥ããã®ã§ãããã©ããå¤å®ããéå»ã®æ¤ç´¢ã¯ã¨ãªã訪åå±¥æ´ã«åºã¥ããèªåè£å®ãã¼ã¿åºä¼ã£ãå ´åã®ã¿ã
é表示ãã¼ã¯ã¼ããå«ãèªåè£å®åè£ãåè£ããé¤ãã¾ãã
ããã¯ãèªåè£å®åè£ã®ãã¡ããã¼ã¯ã¼ããå«ããã®ã¯å
¨ã¦é¤ããã¨ããã¨æ®æ®µã®æ¤ç´¢ã§Googleæ¤ç´¢ã§äººæ°ã®ãã¼ã¯ã¼ãã«åºã¥ãèªåè£å®åè£ãªã©ãæ¶å»ããã¦ãã¾ãããã«ãæ®æ®µã®å©ç¨ã§ä¸ä¾¿ãçãããã¨èããããã§ãã
ä½è«ã§ãããkRestrictedKeywordã«ã¤ãã¦ã¯ã«ã³ãåºåãã«ããã°è¤æ°ãã¼ã¯ã¼ããæå®å¯ã«ãã¦ãããTokenizesKeywordsStringToKeywordsVec(keyword)
ã§tokenizeããã¦ãã¾ãã
User Profileã«é表示ãã¼ã¯ã¼ãã追å ãã
ä¸ã®å¤æ´ã§æå®ããããã¼ã¯ã¼ããå«ãèªåè£å®åè£ãã£ã«ã¿ãªã³ã°ã«ã¤ãã¦ã¯æ©è½ããããã«ãªãã¾ããããã¨ã¯é表示ããããã¼ã¯ã¼ããChromeã®éç¨ã®è¨å®ç»é¢ã§è¿½å ã§ããããã«ãããã¨ã User Profileã«ä¿åãã¦C++å´ããåç §ã§ããããã«å¤æ´ãå ãã¾ãã
Preferenceã«é表示ãã¼ã¯ã¼ãã追å ãã
ã¦ã¼ã¶ã¼ã®ç»é²ããChromiumã®è¨å®ã¯User Profileã®preferenceã«ä¿åãããããããã«åºæã®key(pref_name)ã«ãã£ã¦èå¥ããã¾ãã preferecesã«ä»»æã®è¨å®ã«ã¤ãã¦è¿½å ãããå ´åã«ã¯ã
- PrefNamesã¯ã©ã¹ã§æ°ããè¨å®ãããpreferenceã®nameã¨ããã©ã«ãå¤ãç»é²ããã
- ProfileImplã¯ã©ã¹ã®RegisterProfilePrefsd()ã¨ããé¢æ°ã§ãã®preferenceãç»é²ããã
ã¨ããã¹ãããã§Profileã«ãã®æ°ããpreferenceã®å¤ãã¹ãã¢ãããããã«ãªããPrefServiceãå¼ã¶ãã¨ã§ãC++ã®ããã°ã©ã ããåç
§ã§ããããã«ãªãã¾ãã
preferenceã¸ã®æ°ããªé
ç®ã®è¿½å ã¯chrome/common/pref_names.h
åã³chrome/common/pref_names.cpp
ã«ä»¥ä¸ã®ããã«è¿½å ãã¾ãã
ã¾ãkRestrictedKeyword
ãchrome/common/pref_names.h
ã§å®£è¨ãã¾ãã
namespace prefs { // Profile prefs. Please add Local State prefs below instead. ... extern const char kRestrictedKeyword[]; } // namespace prefs
次ã«ãcppå´ã§UI(JavaScript)å´ãããã®preferenceãåç §ããæã«å¿ è¦ãªpref_nameãç»é²ãã¾ããããã«æ ¼ç´ãããå¤ã¯ããã©ã«ãå¤ã§ã¯ãªãã¦ãã¼ã¨ãã¦ä½¿ãããèå¥åã§ãã
namespace prefs { // *************** PROFILE PREFS *************** // These are attached to the user profile ... const char kRestrictedKeyword[] = "RestrictedKeyword"; } // namespace prefs
æå¾ã«ProfileImplã¯ã©ã¹ã®RegisterProfilePrefsd()ã¨ããé¢æ°ã§ãã®preferenceãç»é²ãã¾ããã¡ãªã¿ã«ããããããªãã¨å®è¡æã«ã³ã¢ãã³ããã¾ãã
// RegisterProfilePrefsd()ã¨ããvoidé¢æ°ã§preferenceã®ç»é²ãè¡ããã¦ãã void ProfileImpl::RegisterProfilePrefs( user_prefs::PrefRegistrySyncable* registry) { registry->RegisterBooleanPref(prefs::kSavingBrowserHistoryDisabled, false); ... registry->RegisterStringPref(prefs::kRestrictedKeyword, std::string()); }
AutocompleteControllerå´ããPrefServiceãå¼ã³åºã
ã¦ã¼ã¶ã¼ã®preferencesãåå¾ããããã«ã¯ãPrefServiceãservice clientããå¼ã¶å¿
è¦ãããã¾ãã
èªåè£å®åè£ã®ã½ã¼ããè¡ãªã£ã¦ããAutocompleteResultã¯ã©ã¹ã¯ãservice clientã«é ãããã®ã«ç´æ¥ã¯ã¢ã¯ã»ã¹ã§ããªããããAutocompleteControllerå´ã§kRestrictedKeywordãåå¾ããSortAndCullWithKeyword()
é¢æ°ã«æ¸¡ãå½¢ã§å®è£
ãããã¨ã«ãã¾ããã
void AutocompleteController::UpdateResult( bool regenerate_result, bool force_notify_default_match_changed) { PrefService* prefs = provider_client_->GetPrefs(); const std::string keyword = prefs->GetString(prefs::kRestrictedKeyword); // é表示ãã¼ã¯ã¼ããè¨å®ããã¦ããæã¯SortAndCullWithKeyword()ãã // ããã§ãªãæã¯é常ã®SortAndCull()ãå¼ã¶ã if (keyword) { result_.SortAndCullWithKeyword(input_, template_url_service_, keyword); } else { result_.SortAndCull(input_, template_url_service_); } ... }
è¨å®ç»é¢ã«é表示ãã¼ã¯ã¼ãç»é²æ¬ã追å ãã
ããã¾ã§ã®å¤æ´ã§preferenceã®æ
å ±ãåå¾ããç»é²ãããä»»æã®ä¸ã¤ãããã¯è¤æ°ã®ãã¼ã¯ã¼ããå«ãèªåè£å®åè£ã®ãã£ã«ã¿ãªã³ãªã³ã°æ©è½ã®å®è£
ãå®äºãã¾ããã
ãã¨ã¯å®éã«Chromeã®ããã©ã«ãã®è¨å®ç»é¢ã«é表示ãã¼ã¯ã¼ããç»é²ã§ããããã«UIãå¤æ´ããã°å®æã§ãã
WebUIãå¤æ´ãã
ã¾ãè¨å®ç»é¢ã®HTML, JavaScriptãã¡ã¤ã«ã追å ãªããå¤æ´ããã¦ãé表示ãã¼ã¯ã¼ããç»é²ããã»ã¯ã·ã§ã³ã追å ãã¾ãã
WebUIã®å¤æ´ã«ã¤ãã¦ã¯åããã¼ã ã®elechoããã以ä¸ã®è¨äºã§è©³ç´°ã«ã¾ã¨ãã¦ãããã¦ããã®ã§èå³ãããæ¹ã¯elechoããã®è¨äºãå¼ãã§ãã ãã :)
elecho.hatenablog.com elecho.hatenablog.com
Chromeã®WebUIã®å¤æ´ã«ã¤ãã¦ã¯ä»¥ä¸ã®ããã¥ã¡ã³ããåèã«ãªãã¾ããã
ããã¥ã¡ã³ãã«ãããããã«ãWebUIã®å¤æ´ã«ã¯WebUIãã¼ã¸ã®ä½æã ãã§ãªãããªã½ã¼ã¹ã¸ã®è¿½å ãã«ã¼ãã£ã³ã°ã®è¨å®çãå¤ãã®ãã¡ã¤ã«ã®å¤æ´ãå¿
è¦ã¨ãªãã
ã©ããå¿ããã¨æ£ãã表示ãããªãã£ãããã¦ãã¾ããããã¯ãããæ¹æ³ãããããè¦å´ãã¾ããâ¦
Chromeã§ã®ããWebUIã®ãããã°æ¹æ³ãç¥ããããªã¨ã¡ãã£ã¨æãã¾ããã
å®éã«Chrome Settingsã«ãã¼ã¯ã¼ãç»é²ã»ã¯ã·ã§ã³ã追å ãã¾ããã(ç»åã¯ææ¥å ã§ã®ãã¢ç¨ã«è¨å®ç»é¢ã®ä¸çªä¸ã«é表示ãã¼ã¯ã¼ãç»é²ã»ã¯ã·ã§ã³ã追å ãã¦ã¿ã¾ã)
callbackãã³ãã©ã追å ãã
ããã¥ã¡ã³ãã«ãç´¹ä»ããã¦ãã¾ãããæ°ãã«è¿½å ããWebUIããC++ã¢ã¸ã¥ã¼ã«ã®æ å ±ãåç §ããããJavaScriptå´ã§ã®settingsã§ã®å¤æ´ãC++ã®PrefServiceãç¨ãã¦user profileã«è¿½å ããããã«ã¯ã ã¡ãã»ã¼ã¸ã³ã¼ã«ããã¯ãã³ãã©ã追å ããæ¹æ³ãæ¨å¥¨ããã¦ãã(ã¿ããã§ã)ã
You probably want your new WebUI page to be able to do something or get information from the C++ world. For this, we use message callback handlers. Let's say that we don't trust the Javascript engine to be able to add two integers together (since we know that it uses floating point values internally). We could add a callback handler to perform integer arithmetic for us.
ããã«ã¤ãã¦ã¯ç¹ã«ææ¢ãã§è¡ãªã£ãé¨åãå¤ãã誤ããªã©ããããããã¾ãããã以ä¸ã®ãããªæé ã§callbackãã³ãã©ã¯ã©ã¹ã追å ãã¾ããã
- handlerã¯ã©ã¹(h, cppãã¡ã¤ã«)ã追å ããã
- MessageCallbackãç»é²ããJavaScriptã§å¼ã°ããé¢æ°åã¨å¯¾å¿ããC++ããã°ã©ã ã§ã®é¢æ°åã決ãã
- å®éã«å¼ã°ããC++ã®é¢æ°ã®åä½ãå®ç¾©ãã
- 追å ãããã³ãã©ãæ°ãããã«ãã¿ã¼ã²ããã«è¿½å ãã
handlerã¯ã©ã¹ã追å ãã
æ°ããmessage callback handlerã追å ããå ´åã«ã¯chrome/browser/ui/webui/settings/
以ä¸ã«settings_restricted_keyword_pages_handler.h
ã¨settings_restricted_keyword_pages_handler.cpp
ãã¡ã¤ã«ãå ããè¨å®ç»é¢ã®å¥ã®ã»ã¯ã·ã§ã³ã®callback handlerãåèã«å®è£
ãã¾ããã
RestrictedKeywordHandlerã¯ã©ã¹ã®ããããã¡ã¤ã«ã¯ãããªæãã
class RestrictedKeywordHandler : public SettingsPageUIHandler, public ui::TableModelObserver { public: explicit RestrictedKeywordHandler(content::WebUI* webui); ~RestrictedKeywordHandler() override; // SettingsPageUIHandler: void RegisterMessages() override; void OnJavascriptAllowed() override; void OnJavascriptDisallowed() override; // ui::TableModelObserver: void OnModelChanged() override; void OnItemsChanged(int start, int length) override; void OnItemsAdded(int start, int length) override; void OnItemsRemoved(int start, int length) override; private: PrefChangeRegistrar pref_change_registrar_; CustomHomePagesTableModel restricted_custom_page_table_model_; DISALLOW_COPY_AND_ASSIGN(RestrictedKeywordHandler); };
MessageCallbackãç»é²ãã
callback handlerã¯ã©ã¹ã§å®ç¾©ãããC++ã®é¢æ°ãMessageCallbackã«ç»é²ãããã¨ã§ãJavaScriptããæå®ããé¢æ°åã§å¼ã¹ã°registerããC++ã®é¢æ°ãå¼ã°ããããã«ãªãã¾ãã
ä»åã¯prefs::kRestrictedKeywordã追å ããé¢æ°setRestrictedKeywordãã¾ãã¦ã¼ã¶ã¼ãè¨å®ç»é¢ãéããæã«ä»ã®è¨å®å¤ãè¦ããããã«JavaScriptã«æ
å ±ã渡ãããã®é¢æ°getRestrictedKeywordã追å ãã¾ãã
å
ã»ã©ä½æããsettings_restricted_keyword_pages_handler.cpp
ã®RestrictedKeywordHandler::RegisterMessages()
ã§ç»é²ãè¡ãã¾ãã
void RestrictedKeywordHandler::RegisterMessages() { if (Profile::FromWebUI(web_ui())->IsOffTheRecord()) return; web_ui()->RegisterMessageCallback("setRestrictedKeyword", base::Bind(&RestrictedKeywordHandler::HandleSetRestrictedKeyword, base::Unretained(this))); web_ui()->RegisterMessageCallback("getRestrictedKeyword", base::Bind(&RestrictedKeywordHandler::HandleGetRestrictedKeyword, base::Unretained(this))); }
å®éã«å®è¡ãããC++é¢æ°ã追å ãã
å®éã«user profileãåå¾ãã¦ç»é²ããããã¼ã¯ã¼ãã®æ
å ±ãåãåºããããè¨å®ç»é¢ã§ãã¼ã¯ã¼ããç»é²ãããéã«preferenceãå¤æ´ããé¢æ°ãsettings_restricted_keyword_pages_handler.cpp
ã«å®è£
ãã¦ããã¾ããHandleAddRestrictedKeyword()
ã§ã¯WebUIããProfileãåå¾ããJavaScriptå´ãã渡ãããvalue
(æ°ãã追å ããããã¼ã¯ã¼ã)ãprefs::kRestrictedKeyword
ã«ã»ãããã¾ããã¾ãã
C++å´ã§preferenceããç¾å¨ã®ãã¼ã¯ã¼ããåå¾ããJavaScriptã«callbackãè¿ãããã®HandleGetRestrictedKeyword()
é¢æ°ã追å ãã¾ãã
void RestrictedKeywordHandler::HandleAddRestrictedKeyword(const base::ListValue* args) { std::string pref_name; args->GetString(0, &pref_name); const base::Value* value; args->Get(1, &value); PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); prefs->SetString(prefs::kRestrictedKeyword, value->GetString()); } void RestrictedKeywordHandler::HandleGetRestrictedKeyword(const base::ListValue* args) { CHECK_EQ(1U, args->GetSize()); const base::Value* callback_id; CHECK(args->Get(0, &callback_id)); AllowJavascript(); ResolveJavascriptCallback(*callback_id, base::Value(GetRestrictedKeyword())); } std::string RestrictedKeywordHandler::GetRestrictedKeyword() { std::string RestrictedKeyword; PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); RestrictedKeyword = prefs->GetString(prefs::kRestrictedKeyword); return RestrictedKeyword; }
ãã«ãã¿ã¼ã²ããã«è¿½å ãã
æ°ããsourcesã追å ããæã¯gnãã¡ã¤ã«ã«è¿½å ãããã¡ã¤ã«ã¸ã®ãã¹ãç»é²ããããã«ãã¿ã¼ã²ããã«è¿½å ãã¾ãã
é常ã¯chrome/browser/ui/BUILD.gn
ã«ccãã¡ã¤ã«ã¨hãã¡ã¤ã«ã¸ã®ãã¹ã追å ããã®ã¿ã§ããã
è¨å®ç»é¢ã®å¤æ´ã«ã¤ãã¦ã¯å¥ã«SettingPagesHandler
ã¨ãã¦chrome/browser/ui/webui/settings/md_settings_ui.cc
ã«ä»¥ä¸ã®ããã«è¿½å ããå¿
è¦ãããã¾ããã
ãã®è¾ºãã«ã¤ãã¦ã¯é¡ä¼¼ããã¯ã©ã¹ãåç
§ããªããå¿
è¦ãããªå¤æ´ã«ããããã¤ãã¦ããã¾ããã
#include "chrome/browser/ui/webui/settings/settings_restricted_keyword_pages_handler.h" MdSettingsUI::MdSettingsUI(content::WebUI* web_ui) : content::WebUIController(web_ui), WebContentsObserver(web_ui->GetWebContents()) { ... AddSettingsPageUIHandler(base::MakeUnique<RestrictedKeywordHandler>(web_ui)); ... }
ã¾ã¨ã
çãæéã§ããããChromiumã®ã½ã¼ã¹ã³ã¼ããã³ã¼ããµã¼ããdesign docããã«æ´»ç¨ãã¦ææ¢ãä¸ã§ã
ãã©ã¦ã¶ã§ã®ãã¾ãã¾ãªããã»ã¹ã®åããC++ä¸çã¨JavaScriptã®ä¸çã§ã©ãããã¨ãããªããã¦ããããã¾ãChromiumã§ã®WebUIã®æ§æãªã©
æ§ã
ãªãã¨ãå¦ã¹ã¾ããã
Chromiumã«å®éã«ã³ãããããªãã¦ããããããªæ©è½ã§ããªãããªâ¦!!ããããã®æ°æã¡ã§è²ã
ããã£ã¦ã¿ãã¨ã¨ã¦ãåå¼·ã«ãªãã®ã§
å¹´æ«å¹´å§æãªæ¹ãªã©ã¯éãã§ã¿ã¦ãã ããã :)