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

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

Issue 9003014: Replace WebUI::tab_contents() with web_contents() and switch all users to use web_contents.h inst... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/bookmarks/bookmark_manager_extension_api.h" 12 #include "chrome/browser/bookmarks/bookmark_manager_extension_api.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/image_loading_tracker.h" 14 #include "chrome/browser/extensions/image_loading_tracker.h"
15 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/browser/prefs/scoped_user_pref_update.h" 16 #include "chrome/browser/prefs/scoped_user_pref_update.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
21 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/extensions/extension.h" 22 #include "chrome/common/extensions/extension.h"
23 #include "chrome/common/extensions/extension_constants.h" 23 #include "chrome/common/extensions/extension_constants.h"
24 #include "chrome/common/extensions/extension_icon_set.h" 24 #include "chrome/common/extensions/extension_icon_set.h"
25 #include "chrome/common/extensions/extension_resource.h" 25 #include "chrome/common/extensions/extension_resource.h"
26 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
27 #include "content/browser/tab_contents/tab_contents.h" 27 #include "content/browser/tab_contents/navigation_controller.h"
28 #include "content/public/browser/web_contents.h"
28 #include "content/public/common/page_transition_types.h" 29 #include "content/public/common/page_transition_types.h"
29 #include "content/public/common/bindings_policy.h" 30 #include "content/public/common/bindings_policy.h"
30 #include "net/base/file_stream.h" 31 #include "net/base/file_stream.h"
31 #include "third_party/skia/include/core/SkBitmap.h" 32 #include "third_party/skia/include/core/SkBitmap.h"
32 #include "ui/gfx/codec/png_codec.h" 33 #include "ui/gfx/codec/png_codec.h"
33 #include "ui/gfx/favicon_size.h" 34 #include "ui/gfx/favicon_size.h"
34 35
36 using content::WebContents;
37
35 namespace { 38 namespace {
36 39
37 // De-dupes the items in |list|. Assumes the values are strings. 40 // De-dupes the items in |list|. Assumes the values are strings.
38 void CleanUpDuplicates(ListValue* list) { 41 void CleanUpDuplicates(ListValue* list) {
39 std::set<std::string> seen_values; 42 std::set<std::string> seen_values;
40 43
41 // Loop backwards as we may be removing items. 44 // Loop backwards as we may be removing items.
42 for (size_t i = list->GetSize() - 1; (i + 1) > 0; --i) { 45 for (size_t i = list->GetSize() - 1; (i + 1) > 0; --i) {
43 std::string value; 46 std::string value;
44 if (!list->GetString(i, &value)) { 47 if (!list->GetString(i, &value)) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 const Extension* extension_; 120 const Extension* extension_;
118 121
119 DISALLOW_COPY_AND_ASSIGN(ExtensionWebUIImageLoadingTracker); 122 DISALLOW_COPY_AND_ASSIGN(ExtensionWebUIImageLoadingTracker);
120 }; 123 };
121 124
122 } // namespace 125 } // namespace
123 126
124 const char ExtensionWebUI::kExtensionURLOverrides[] = 127 const char ExtensionWebUI::kExtensionURLOverrides[] =
125 "extensions.chrome_url_overrides"; 128 "extensions.chrome_url_overrides";
126 129
127 ExtensionWebUI::ExtensionWebUI(TabContents* tab_contents, const GURL& url) 130 ExtensionWebUI::ExtensionWebUI(WebContents* web_contents, const GURL& url)
128 : ChromeWebUI(tab_contents), 131 : ChromeWebUI(web_contents),
129 url_(url) { 132 url_(url) {
130 Profile* profile = 133 Profile* profile =
131 Profile::FromBrowserContext(tab_contents->GetBrowserContext()); 134 Profile::FromBrowserContext(web_contents->GetBrowserContext());
132 ExtensionService* service = profile->GetExtensionService(); 135 ExtensionService* service = profile->GetExtensionService();
133 const Extension* extension = 136 const Extension* extension =
134 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url)); 137 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
135 DCHECK(extension); 138 DCHECK(extension);
136 // 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
137 // component apps like bookmark manager. 140 // component apps like bookmark manager.
138 should_hide_url_ = !extension->is_hosted_app(); 141 should_hide_url_ = !extension->is_hosted_app();
139 142
140 // The base class defaults to enabling WebUI bindings, but we don't need 143 // The base class defaults to enabling WebUI bindings, but we don't need
141 // those (this is also reflected in ChromeWebUIFactory:: 144 // those (this is also reflected in ChromeWebUIFactory::
142 // UseWebUIBindingsForURL). 145 // UseWebUIBindingsForURL).
143 bindings_ = 0; 146 bindings_ = 0;
144 147
145 // Bind externalHost to Extension WebUI loaded in Chrome Frame. 148 // Bind externalHost to Extension WebUI loaded in Chrome Frame.
146 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 149 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
147 if (browser_command_line.HasSwitch(switches::kChromeFrame)) 150 if (browser_command_line.HasSwitch(switches::kChromeFrame))
148 bindings_ |= content::BINDINGS_POLICY_EXTERNAL_HOST; 151 bindings_ |= content::BINDINGS_POLICY_EXTERNAL_HOST;
149 // For chrome:// overrides, some of the defaults are a little different. 152 // For chrome:// overrides, some of the defaults are a little different.
150 GURL effective_url = tab_contents->GetURL(); 153 GURL effective_url = web_contents->GetURL();
151 if (effective_url.SchemeIs(chrome::kChromeUIScheme)) { 154 if (effective_url.SchemeIs(chrome::kChromeUIScheme)) {
152 if (effective_url.host() == chrome::kChromeUINewTabHost) { 155 if (effective_url.host() == chrome::kChromeUINewTabHost) {
153 focus_location_bar_by_default_ = true; 156 focus_location_bar_by_default_ = true;
154 } else { 157 } else {
155 // Current behavior of other chrome:// pages is to display the URL. 158 // Current behavior of other chrome:// pages is to display the URL.
156 should_hide_url_ = false; 159 should_hide_url_ = false;
157 } 160 }
158 } 161 }
159 162
160 // Hack: A few things we specialize just for the bookmark manager. 163 // Hack: A few things we specialize just for the bookmark manager.
161 if (extension->id() == extension_misc::kBookmarkManagerId) { 164 if (extension->id() == extension_misc::kBookmarkManagerId) {
162 TabContentsWrapper* tab = 165 TabContentsWrapper* tab =
163 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_); 166 TabContentsWrapper::GetCurrentWrapperForContents(web_contents);
164 DCHECK(tab); 167 DCHECK(tab);
165 bookmark_manager_extension_event_router_.reset( 168 bookmark_manager_extension_event_router_.reset(
166 new BookmarkManagerExtensionEventRouter(profile, tab)); 169 new BookmarkManagerExtensionEventRouter(profile, tab));
167 170
168 link_transition_type_ = content::PAGE_TRANSITION_AUTO_BOOKMARK; 171 link_transition_type_ = content::PAGE_TRANSITION_AUTO_BOOKMARK;
169 } 172 }
170 } 173 }
171 174
172 ExtensionWebUI::~ExtensionWebUI() {} 175 ExtensionWebUI::~ExtensionWebUI() {}
173 176
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 void ExtensionWebUI::UnregisterAndReplaceOverride(const std::string& page, 336 void ExtensionWebUI::UnregisterAndReplaceOverride(const std::string& page,
334 Profile* profile, 337 Profile* profile,
335 ListValue* list, 338 ListValue* list,
336 Value* override) { 339 Value* override) {
337 size_t index = 0; 340 size_t index = 0;
338 bool found = list->Remove(*override, &index); 341 bool found = list->Remove(*override, &index);
339 if (found && index == 0) { 342 if (found && index == 0) {
340 // This is the active override, so we need to find all existing 343 // This is the active override, so we need to find all existing
341 // tabs for this override and get them to reload the original URL. 344 // tabs for this override and get them to reload the original URL.
342 for (TabContentsIterator iterator; !iterator.done(); ++iterator) { 345 for (TabContentsIterator iterator; !iterator.done(); ++iterator) {
343 TabContents* tab = (*iterator)->tab_contents(); 346 WebContents* tab = (*iterator)->web_contents();
344 Profile* tab_profile = 347 Profile* tab_profile =
345 Profile::FromBrowserContext(tab->GetBrowserContext()); 348 Profile::FromBrowserContext(tab->GetBrowserContext());
346 if (tab_profile != profile) 349 if (tab_profile != profile)
347 continue; 350 continue;
348 351
349 GURL url = tab->GetURL(); 352 GURL url = tab->GetURL();
350 if (!url.SchemeIs(chrome::kChromeUIScheme) || url.host() != page) 353 if (!url.SchemeIs(chrome::kChromeUIScheme) || url.host() != page)
351 continue; 354 continue;
352 355
353 // Don't use Reload() since |url| isn't the same as the internal URL 356 // Don't use Reload() since |url| isn't the same as the internal URL
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 } 405 }
403 406
404 // static 407 // static
405 void ExtensionWebUI::GetFaviconForURL(Profile* profile, 408 void ExtensionWebUI::GetFaviconForURL(Profile* profile,
406 FaviconService::GetFaviconRequest* request, const GURL& page_url) { 409 FaviconService::GetFaviconRequest* request, const GURL& page_url) {
407 // tracker deletes itself when done. 410 // tracker deletes itself when done.
408 ExtensionWebUIImageLoadingTracker* tracker = 411 ExtensionWebUIImageLoadingTracker* tracker =
409 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); 412 new ExtensionWebUIImageLoadingTracker(profile, request, page_url);
410 tracker->Init(); 413 tracker->Init();
411 } 414 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_web_ui.h ('k') | chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698