Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: chrome/browser/extensions/extension_web_ui.cc

Issue 7464009: Removal of Profile from content part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: works now Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 = static_cast<Profile*>(tab_contents->context());
133 ExtensionService* service = profile->GetExtensionService();
133 const Extension* extension = service->GetExtensionByURL(url); 134 const Extension* extension = service->GetExtensionByURL(url);
134 if (!extension) 135 if (!extension)
135 extension = service->GetExtensionByWebExtent(url); 136 extension = service->GetExtensionByWebExtent(url);
136 DCHECK(extension); 137 DCHECK(extension);
137 // Only hide the url for internal pages (e.g. chrome-extension or packaged 138 // Only hide the url for internal pages (e.g. chrome-extension or packaged
138 // component apps like bookmark manager. 139 // component apps like bookmark manager.
139 should_hide_url_ = !extension->is_hosted_app(); 140 should_hide_url_ = !extension->is_hosted_app();
140 141
141 // The base class defaults to enabling web ui bindings, but we don't need 142 // The base class defaults to enabling web ui bindings, but we don't need
142 // those. 143 // those.
(...skipping 13 matching lines...) Expand all
156 should_hide_url_ = false; 157 should_hide_url_ = false;
157 } 158 }
158 } 159 }
159 160
160 // Hack: A few things we specialize just for the bookmark manager. 161 // Hack: A few things we specialize just for the bookmark manager.
161 if (extension->id() == extension_misc::kBookmarkManagerId) { 162 if (extension->id() == extension_misc::kBookmarkManagerId) {
162 TabContentsWrapper* tab = 163 TabContentsWrapper* tab =
163 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_); 164 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_);
164 DCHECK(tab); 165 DCHECK(tab);
165 extension_bookmark_manager_event_router_.reset( 166 extension_bookmark_manager_event_router_.reset(
166 new ExtensionBookmarkManagerEventRouter(GetProfile(), tab)); 167 new ExtensionBookmarkManagerEventRouter(profile, tab));
167 168
168 link_transition_type_ = PageTransition::AUTO_BOOKMARK; 169 link_transition_type_ = PageTransition::AUTO_BOOKMARK;
169 } 170 }
170 } 171 }
171 172
172 ExtensionWebUI::~ExtensionWebUI() {} 173 ExtensionWebUI::~ExtensionWebUI() {}
173 174
174 ExtensionBookmarkManagerEventRouter* 175 ExtensionBookmarkManagerEventRouter*
175 ExtensionWebUI::extension_bookmark_manager_event_router() { 176 ExtensionWebUI::extension_bookmark_manager_event_router() {
176 return extension_bookmark_manager_event_router_.get(); 177 return extension_bookmark_manager_event_router_.get();
177 } 178 }
178 179
179 //////////////////////////////////////////////////////////////////////////////// 180 ////////////////////////////////////////////////////////////////////////////////
180 // chrome:// URL overrides 181 // chrome:// URL overrides
181 182
182 // static 183 // static
183 void ExtensionWebUI::RegisterUserPrefs(PrefService* prefs) { 184 void ExtensionWebUI::RegisterUserPrefs(PrefService* prefs) {
184 prefs->RegisterDictionaryPref(kExtensionURLOverrides, 185 prefs->RegisterDictionaryPref(kExtensionURLOverrides,
185 PrefService::UNSYNCABLE_PREF); 186 PrefService::UNSYNCABLE_PREF);
186 } 187 }
187 188
188 // static 189 // static
189 bool ExtensionWebUI::HandleChromeURLOverride(GURL* url, Profile* profile) { 190 bool ExtensionWebUI::HandleChromeURLOverride(GURL* url,
191 content::BrowserContext* context) {
190 if (!url->SchemeIs(chrome::kChromeUIScheme)) 192 if (!url->SchemeIs(chrome::kChromeUIScheme))
191 return false; 193 return false;
192 194
195 Profile* profile = static_cast<Profile*>(context);
193 const DictionaryValue* overrides = 196 const DictionaryValue* overrides =
194 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides); 197 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides);
195 std::string page = url->host(); 198 std::string page = url->host();
196 ListValue* url_list; 199 ListValue* url_list;
197 if (!overrides || !overrides->GetList(page, &url_list)) 200 if (!overrides || !overrides->GetList(page, &url_list))
198 return false; 201 return false;
199 202
200 ExtensionService* service = profile->GetExtensionService(); 203 ExtensionService* service = profile->GetExtensionService();
201 204
202 size_t i = 0; 205 size_t i = 0;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 continue; 245 continue;
243 } 246 }
244 247
245 *url = extension_url; 248 *url = extension_url;
246 return true; 249 return true;
247 } 250 }
248 return false; 251 return false;
249 } 252 }
250 253
251 // static 254 // static
252 bool ExtensionWebUI::HandleChromeURLOverrideReverse(GURL* url, 255 bool ExtensionWebUI::HandleChromeURLOverrideReverse(
253 Profile* profile) { 256 GURL* url, content::BrowserContext* context) {
257 Profile* profile = static_cast<Profile*>(context);
254 const DictionaryValue* overrides = 258 const DictionaryValue* overrides =
255 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides); 259 profile->GetPrefs()->GetDictionary(kExtensionURLOverrides);
256 if (!overrides) 260 if (!overrides)
257 return false; 261 return false;
258 262
259 // Find the reverse mapping based on the given URL. For example this maps the 263 // Find the reverse mapping based on the given URL. For example this maps the
260 // internal URL chrome-extension://eemcgdkndhakfknomggombfjeno/main.html#1 to 264 // internal URL chrome-extension://eemcgdkndhakfknomggombfjeno/main.html#1 to
261 // chrome://bookmarks/#1 for display in the omnibox. 265 // chrome://bookmarks/#1 for display in the omnibox.
262 for (DictionaryValue::key_iterator it = overrides->begin_keys(), 266 for (DictionaryValue::key_iterator it = overrides->begin_keys(),
263 end = overrides->end_keys(); it != end; ++it) { 267 end = overrides->end_keys(); it != end; ++it) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 331
328 // static 332 // static
329 void ExtensionWebUI::UnregisterAndReplaceOverride(const std::string& page, 333 void ExtensionWebUI::UnregisterAndReplaceOverride(const std::string& page,
330 Profile* profile, ListValue* list, Value* override) { 334 Profile* profile, ListValue* list, Value* override) {
331 int index = list->Remove(*override); 335 int index = list->Remove(*override);
332 if (index == 0) { 336 if (index == 0) {
333 // This is the active override, so we need to find all existing 337 // 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. 338 // tabs for this override and get them to reload the original URL.
335 for (TabContentsIterator iterator; !iterator.done(); ++iterator) { 339 for (TabContentsIterator iterator; !iterator.done(); ++iterator) {
336 TabContents* tab = (*iterator)->tab_contents(); 340 TabContents* tab = (*iterator)->tab_contents();
337 if (tab->profile() != profile) 341 Profile* tab_profile = static_cast<Profile*>(tab->context());
342 if (tab_profile != profile)
338 continue; 343 continue;
339 344
340 GURL url = tab->GetURL(); 345 GURL url = tab->GetURL();
341 if (!url.SchemeIs(chrome::kChromeUIScheme) || url.host() != page) 346 if (!url.SchemeIs(chrome::kChromeUIScheme) || url.host() != page)
342 continue; 347 continue;
343 348
344 // Don't use Reload() since |url| isn't the same as the internal URL 349 // Don't use Reload() since |url| isn't the same as the internal URL
345 // that NavigationController has. 350 // that NavigationController has.
346 tab->controller().LoadURL(url, url, PageTransition::RELOAD); 351 tab->controller().LoadURL(url, url, PageTransition::RELOAD);
347 } 352 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 396 }
392 397
393 // static 398 // static
394 void ExtensionWebUI::GetFaviconForURL(Profile* profile, 399 void ExtensionWebUI::GetFaviconForURL(Profile* profile,
395 FaviconService::GetFaviconRequest* request, const GURL& page_url) { 400 FaviconService::GetFaviconRequest* request, const GURL& page_url) {
396 // tracker deletes itself when done. 401 // tracker deletes itself when done.
397 ExtensionWebUIImageLoadingTracker* tracker = 402 ExtensionWebUIImageLoadingTracker* tracker =
398 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); 403 new ExtensionWebUIImageLoadingTracker(profile, request, page_url);
399 tracker->Init(); 404 tracker->Init();
400 } 405 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698