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

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

Issue 9224002: Make WebUI objects not derive from WebUI. WebUI objects own the controller. This is the ownership... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync to head to clear linux_chromeos browsertest failures 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/webui/web_ui.h"
27 #include "content/public/browser/navigation_controller.h" 28 #include "content/public/browser/navigation_controller.h"
28 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
29 #include "content/public/common/page_transition_types.h" 30 #include "content/public/common/page_transition_types.h"
30 #include "content/public/common/bindings_policy.h" 31 #include "content/public/common/bindings_policy.h"
31 #include "net/base/file_stream.h" 32 #include "net/base/file_stream.h"
32 #include "third_party/skia/include/core/SkBitmap.h" 33 #include "third_party/skia/include/core/SkBitmap.h"
33 #include "ui/gfx/codec/png_codec.h" 34 #include "ui/gfx/codec/png_codec.h"
34 #include "ui/gfx/favicon_size.h" 35 #include "ui/gfx/favicon_size.h"
35 36
36 using content::WebContents; 37 using content::WebContents;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 const Extension* extension_; 121 const Extension* extension_;
121 122
122 DISALLOW_COPY_AND_ASSIGN(ExtensionWebUIImageLoadingTracker); 123 DISALLOW_COPY_AND_ASSIGN(ExtensionWebUIImageLoadingTracker);
123 }; 124 };
124 125
125 } // namespace 126 } // namespace
126 127
127 const char ExtensionWebUI::kExtensionURLOverrides[] = 128 const char ExtensionWebUI::kExtensionURLOverrides[] =
128 "extensions.chrome_url_overrides"; 129 "extensions.chrome_url_overrides";
129 130
130 ExtensionWebUI::ExtensionWebUI(WebContents* web_contents, const GURL& url) 131 ExtensionWebUI::ExtensionWebUI(WebUI* web_ui, const GURL& url)
131 : WebUI(web_contents, this), 132 : WebUIController(web_ui),
132 url_(url) { 133 url_(url) {
133 Profile* profile = 134 Profile* profile =
134 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 135 Profile::FromBrowserContext(web_ui->web_contents()->GetBrowserContext());
135 ExtensionService* service = profile->GetExtensionService(); 136 ExtensionService* service = profile->GetExtensionService();
136 const Extension* extension = 137 const Extension* extension =
137 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url)); 138 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
138 DCHECK(extension); 139 DCHECK(extension);
139 // Only hide the url for internal pages (e.g. chrome-extension or packaged 140 // Only hide the url for internal pages (e.g. chrome-extension or packaged
140 // component apps like bookmark manager. 141 // component apps like bookmark manager.
141 should_hide_url_ = !extension->is_hosted_app(); 142 bool should_hide_url = !extension->is_hosted_app();
142 143
143 // The base class defaults to enabling WebUI bindings, but we don't need 144 // The base class defaults to enabling WebUI bindings, but we don't need
144 // those (this is also reflected in ChromeWebUIFactory:: 145 // those (this is also reflected in ChromeWebUIFactory::
145 // UseWebUIBindingsForURL). 146 // UseWebUIBindingsForURL).
146 bindings_ = 0; 147 int bindings = 0;
147 148
148 // Bind externalHost to Extension WebUI loaded in Chrome Frame. 149 // Bind externalHost to Extension WebUI loaded in Chrome Frame.
149 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 150 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
150 if (browser_command_line.HasSwitch(switches::kChromeFrame)) 151 if (browser_command_line.HasSwitch(switches::kChromeFrame))
151 bindings_ |= content::BINDINGS_POLICY_EXTERNAL_HOST; 152 bindings |= content::BINDINGS_POLICY_EXTERNAL_HOST;
152 // For chrome:// overrides, some of the defaults are a little different. 153 // For chrome:// overrides, some of the defaults are a little different.
153 GURL effective_url = web_contents->GetURL(); 154 GURL effective_url = web_ui->web_contents()->GetURL();
154 if (effective_url.SchemeIs(chrome::kChromeUIScheme)) { 155 if (effective_url.SchemeIs(chrome::kChromeUIScheme)) {
155 if (effective_url.host() == chrome::kChromeUINewTabHost) { 156 if (effective_url.host() == chrome::kChromeUINewTabHost) {
156 focus_location_bar_by_default_ = true; 157 web_ui->FocusLocationBarByDefault();
157 } else { 158 } else {
158 // Current behavior of other chrome:// pages is to display the URL. 159 // Current behavior of other chrome:// pages is to display the URL.
159 should_hide_url_ = false; 160 should_hide_url = false;
160 } 161 }
161 } 162 }
162 163
164 if (should_hide_url)
165 web_ui->HideURL();
166
167 web_ui->SetBindings(bindings);
168
163 // Hack: A few things we specialize just for the bookmark manager. 169 // Hack: A few things we specialize just for the bookmark manager.
164 if (extension->id() == extension_misc::kBookmarkManagerId) { 170 if (extension->id() == extension_misc::kBookmarkManagerId) {
165 TabContentsWrapper* tab = 171 TabContentsWrapper* tab = TabContentsWrapper::GetCurrentWrapperForContents(
166 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); 172 web_ui->web_contents());
167 DCHECK(tab); 173 DCHECK(tab);
168 bookmark_manager_extension_event_router_.reset( 174 bookmark_manager_extension_event_router_.reset(
169 new BookmarkManagerExtensionEventRouter(profile, tab)); 175 new BookmarkManagerExtensionEventRouter(profile, tab));
170 176
171 link_transition_type_ = content::PAGE_TRANSITION_AUTO_BOOKMARK; 177 web_ui->SetLinkTransitionType(content::PAGE_TRANSITION_AUTO_BOOKMARK);
172 } 178 }
173 } 179 }
174 180
175 ExtensionWebUI::~ExtensionWebUI() {} 181 ExtensionWebUI::~ExtensionWebUI() {}
176 182
177 BookmarkManagerExtensionEventRouter* 183 BookmarkManagerExtensionEventRouter*
178 ExtensionWebUI::bookmark_manager_extension_event_router() { 184 ExtensionWebUI::bookmark_manager_extension_event_router() {
179 return bookmark_manager_extension_event_router_.get(); 185 return bookmark_manager_extension_event_router_.get();
180 } 186 }
181 187
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } 411 }
406 412
407 // static 413 // static
408 void ExtensionWebUI::GetFaviconForURL(Profile* profile, 414 void ExtensionWebUI::GetFaviconForURL(Profile* profile,
409 FaviconService::GetFaviconRequest* request, const GURL& page_url) { 415 FaviconService::GetFaviconRequest* request, const GURL& page_url) {
410 // tracker deletes itself when done. 416 // tracker deletes itself when done.
411 ExtensionWebUIImageLoadingTracker* tracker = 417 ExtensionWebUIImageLoadingTracker* tracker =
412 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); 418 new ExtensionWebUIImageLoadingTracker(profile, request, page_url);
413 tracker->Init(); 419 tracker->Init();
414 } 420 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698