| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/extension_web_ui.h" | 5 #include "chrome/browser/extensions/extension_web_ui.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 } // namespace | 124 } // namespace |
| 125 | 125 |
| 126 const char ExtensionWebUI::kExtensionURLOverrides[] = | 126 const char ExtensionWebUI::kExtensionURLOverrides[] = |
| 127 "extensions.chrome_url_overrides"; | 127 "extensions.chrome_url_overrides"; |
| 128 | 128 |
| 129 ExtensionWebUI::ExtensionWebUI(TabContents* tab_contents, const GURL& url) | 129 ExtensionWebUI::ExtensionWebUI(TabContents* tab_contents, const GURL& url) |
| 130 : ChromeWebUI(tab_contents), | 130 : ChromeWebUI(tab_contents), |
| 131 url_(url) { | 131 url_(url) { |
| 132 ExtensionService* service = tab_contents->profile()->GetExtensionService(); | 132 Profile* profile = |
| 133 Profile::FromBrowserContext(tab_contents->browser_context()); |
| 134 ExtensionService* service = profile->GetExtensionService(); |
| 133 const Extension* extension = service->GetExtensionByURL(url); | 135 const Extension* extension = service->GetExtensionByURL(url); |
| 134 if (!extension) | 136 if (!extension) |
| 135 extension = service->GetExtensionByWebExtent(url); | 137 extension = service->GetExtensionByWebExtent(url); |
| 136 DCHECK(extension); | 138 DCHECK(extension); |
| 137 // Only hide the url for internal pages (e.g. chrome-extension or packaged | 139 // Only hide the url for internal pages (e.g. chrome-extension or packaged |
| 138 // component apps like bookmark manager. | 140 // component apps like bookmark manager. |
| 139 should_hide_url_ = !extension->is_hosted_app(); | 141 should_hide_url_ = !extension->is_hosted_app(); |
| 140 | 142 |
| 141 // The base class defaults to enabling web ui bindings, but we don't need | 143 // The base class defaults to enabling web ui bindings, but we don't need |
| 142 // those. | 144 // those. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 156 should_hide_url_ = false; | 158 should_hide_url_ = false; |
| 157 } | 159 } |
| 158 } | 160 } |
| 159 | 161 |
| 160 // Hack: A few things we specialize just for the bookmark manager. | 162 // Hack: A few things we specialize just for the bookmark manager. |
| 161 if (extension->id() == extension_misc::kBookmarkManagerId) { | 163 if (extension->id() == extension_misc::kBookmarkManagerId) { |
| 162 TabContentsWrapper* tab = | 164 TabContentsWrapper* tab = |
| 163 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_); | 165 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_); |
| 164 DCHECK(tab); | 166 DCHECK(tab); |
| 165 extension_bookmark_manager_event_router_.reset( | 167 extension_bookmark_manager_event_router_.reset( |
| 166 new ExtensionBookmarkManagerEventRouter(GetProfile(), tab)); | 168 new ExtensionBookmarkManagerEventRouter(profile, tab)); |
| 167 | 169 |
| 168 link_transition_type_ = PageTransition::AUTO_BOOKMARK; | 170 link_transition_type_ = PageTransition::AUTO_BOOKMARK; |
| 169 } | 171 } |
| 170 } | 172 } |
| 171 | 173 |
| 172 ExtensionWebUI::~ExtensionWebUI() {} | 174 ExtensionWebUI::~ExtensionWebUI() {} |
| 173 | 175 |
| 174 ExtensionBookmarkManagerEventRouter* | 176 ExtensionBookmarkManagerEventRouter* |
| 175 ExtensionWebUI::extension_bookmark_manager_event_router() { | 177 ExtensionWebUI::extension_bookmark_manager_event_router() { |
| 176 return extension_bookmark_manager_event_router_.get(); | 178 return extension_bookmark_manager_event_router_.get(); |
| 177 } | 179 } |
| 178 | 180 |
| 179 //////////////////////////////////////////////////////////////////////////////// | 181 //////////////////////////////////////////////////////////////////////////////// |
| 180 // chrome:// URL overrides | 182 // chrome:// URL overrides |
| 181 | 183 |
| 182 // static | 184 // static |
| 183 void ExtensionWebUI::RegisterUserPrefs(PrefService* prefs) { | 185 void ExtensionWebUI::RegisterUserPrefs(PrefService* prefs) { |
| 184 prefs->RegisterDictionaryPref(kExtensionURLOverrides, | 186 prefs->RegisterDictionaryPref(kExtensionURLOverrides, |
| 185 PrefService::UNSYNCABLE_PREF); | 187 PrefService::UNSYNCABLE_PREF); |
| 186 } | 188 } |
| 187 | 189 |
| 188 // static | 190 // static |
| 189 bool ExtensionWebUI::HandleChromeURLOverride(GURL* url, Profile* profile) { | 191 bool ExtensionWebUI::HandleChromeURLOverride( |
| 192 GURL* url, content::BrowserContext* browser_context) { |
| 190 if (!url->SchemeIs(chrome::kChromeUIScheme)) | 193 if (!url->SchemeIs(chrome::kChromeUIScheme)) |
| 191 return false; | 194 return false; |
| 192 | 195 |
| 196 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 193 const DictionaryValue* overrides = | 197 const DictionaryValue* overrides = |
| 194 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides); | 198 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides); |
| 195 std::string page = url->host(); | 199 std::string page = url->host(); |
| 196 ListValue* url_list; | 200 ListValue* url_list; |
| 197 if (!overrides || !overrides->GetList(page, &url_list)) | 201 if (!overrides || !overrides->GetList(page, &url_list)) |
| 198 return false; | 202 return false; |
| 199 | 203 |
| 200 ExtensionService* service = profile->GetExtensionService(); | 204 ExtensionService* service = profile->GetExtensionService(); |
| 201 | 205 |
| 202 size_t i = 0; | 206 size_t i = 0; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 continue; | 246 continue; |
| 243 } | 247 } |
| 244 | 248 |
| 245 *url = extension_url; | 249 *url = extension_url; |
| 246 return true; | 250 return true; |
| 247 } | 251 } |
| 248 return false; | 252 return false; |
| 249 } | 253 } |
| 250 | 254 |
| 251 // static | 255 // static |
| 252 bool ExtensionWebUI::HandleChromeURLOverrideReverse(GURL* url, | 256 bool ExtensionWebUI::HandleChromeURLOverrideReverse( |
| 253 Profile* profile) { | 257 GURL* url, content::BrowserContext* browser_context) { |
| 258 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 254 const DictionaryValue* overrides = | 259 const DictionaryValue* overrides = |
| 255 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides); | 260 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides); |
| 256 if (!overrides) | 261 if (!overrides) |
| 257 return false; | 262 return false; |
| 258 | 263 |
| 259 // Find the reverse mapping based on the given URL. For example this maps the | 264 // Find the reverse mapping based on the given URL. For example this maps the |
| 260 // internal URL chrome-extension://eemcgdkndhakfknomggombfjeno/main.html#1 to | 265 // internal URL chrome-extension://eemcgdkndhakfknomggombfjeno/main.html#1 to |
| 261 // chrome://bookmarks/#1 for display in the omnibox. | 266 // chrome://bookmarks/#1 for display in the omnibox. |
| 262 for (DictionaryValue::key_iterator it = overrides->begin_keys(), | 267 for (DictionaryValue::key_iterator it = overrides->begin_keys(), |
| 263 end = overrides->end_keys(); it != end; ++it) { | 268 end = overrides->end_keys(); it != end; ++it) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 332 |
| 328 // static | 333 // static |
| 329 void ExtensionWebUI::UnregisterAndReplaceOverride(const std::string& page, | 334 void ExtensionWebUI::UnregisterAndReplaceOverride(const std::string& page, |
| 330 Profile* profile, ListValue* list, Value* override) { | 335 Profile* profile, ListValue* list, Value* override) { |
| 331 int index = list->Remove(*override); | 336 int index = list->Remove(*override); |
| 332 if (index == 0) { | 337 if (index == 0) { |
| 333 // This is the active override, so we need to find all existing | 338 // This is the active override, so we need to find all existing |
| 334 // tabs for this override and get them to reload the original URL. | 339 // tabs for this override and get them to reload the original URL. |
| 335 for (TabContentsIterator iterator; !iterator.done(); ++iterator) { | 340 for (TabContentsIterator iterator; !iterator.done(); ++iterator) { |
| 336 TabContents* tab = (*iterator)->tab_contents(); | 341 TabContents* tab = (*iterator)->tab_contents(); |
| 337 if (tab->profile() != profile) | 342 Profile* tab_profile = |
| 343 Profile::FromBrowserContext(tab->browser_context()); |
| 344 if (tab_profile != profile) |
| 338 continue; | 345 continue; |
| 339 | 346 |
| 340 GURL url = tab->GetURL(); | 347 GURL url = tab->GetURL(); |
| 341 if (!url.SchemeIs(chrome::kChromeUIScheme) || url.host() != page) | 348 if (!url.SchemeIs(chrome::kChromeUIScheme) || url.host() != page) |
| 342 continue; | 349 continue; |
| 343 | 350 |
| 344 // Don't use Reload() since |url| isn't the same as the internal URL | 351 // Don't use Reload() since |url| isn't the same as the internal URL |
| 345 // that NavigationController has. | 352 // that NavigationController has. |
| 346 tab->controller().LoadURL(url, url, PageTransition::RELOAD); | 353 tab->controller().LoadURL(url, url, PageTransition::RELOAD); |
| 347 } | 354 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 } | 398 } |
| 392 | 399 |
| 393 // static | 400 // static |
| 394 void ExtensionWebUI::GetFaviconForURL(Profile* profile, | 401 void ExtensionWebUI::GetFaviconForURL(Profile* profile, |
| 395 FaviconService::GetFaviconRequest* request, const GURL& page_url) { | 402 FaviconService::GetFaviconRequest* request, const GURL& page_url) { |
| 396 // tracker deletes itself when done. | 403 // tracker deletes itself when done. |
| 397 ExtensionWebUIImageLoadingTracker* tracker = | 404 ExtensionWebUIImageLoadingTracker* tracker = |
| 398 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); | 405 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); |
| 399 tracker->Init(); | 406 tracker->Init(); |
| 400 } | 407 } |
| OLD | NEW |