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

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

Issue 6932038: avoid dereferencing NULL extension in ExtensionHost (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed reduntant Created 9 years, 7 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_host.h" 5 #include "chrome/browser/extensions/extension_host.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "chrome/browser/browser_shutdown.h" 13 #include "chrome/browser/browser_shutdown.h"
14 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_tabs_module.h" 15 #include "chrome/browser/extensions/extension_tabs_module.h"
16 #include "chrome/browser/file_select_helper.h" 16 #include "chrome/browser/file_select_helper.h"
17 #include "chrome/browser/platform_util.h" 17 #include "chrome/browser/platform_util.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/renderer_preferences_util.h" 19 #include "chrome/browser/renderer_preferences_util.h"
20 #include "chrome/browser/tab_contents/popup_menu_helper_mac.h" 20 #include "chrome/browser/tab_contents/popup_menu_helper_mac.h"
21 #include "chrome/browser/tabs/tab_strip_model.h" 21 #include "chrome/browser/tabs/tab_strip_model.h"
22 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" 22 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
23 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_list.h" 24 #include "chrome/browser/ui/browser_list.h"
25 #include "chrome/browser/ui/browser_window.h" 25 #include "chrome/browser/ui/browser_window.h"
26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
27 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" 27 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
28 #include "chrome/common/chrome_constants.h" 28 #include "chrome/common/chrome_constants.h"
29 #include "chrome/common/extensions/extension.h"
30 #include "chrome/common/extensions/extension_constants.h" 29 #include "chrome/common/extensions/extension_constants.h"
31 #include "chrome/common/render_messages.h" 30 #include "chrome/common/render_messages.h"
32 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
33 #include "chrome/common/view_types.h" 32 #include "chrome/common/view_types.h"
34 #include "content/browser/browsing_instance.h" 33 #include "content/browser/browsing_instance.h"
35 #include "content/browser/renderer_host/browser_render_process_host.h" 34 #include "content/browser/renderer_host/browser_render_process_host.h"
36 #include "content/browser/renderer_host/render_process_host.h" 35 #include "content/browser/renderer_host/render_process_host.h"
37 #include "content/browser/renderer_host/render_view_host.h" 36 #include "content/browser/renderer_host/render_view_host.h"
38 #include "content/browser/renderer_host/render_widget_host.h" 37 #include "content/browser/renderer_host/render_widget_host.h"
39 #include "content/browser/renderer_host/render_widget_host_view.h" 38 #include "content/browser/renderer_host/render_widget_host_view.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 }; 118 };
120 119
121 //////////////// 120 ////////////////
122 // ExtensionHost 121 // ExtensionHost
123 122
124 ExtensionHost::ExtensionHost(const Extension* extension, 123 ExtensionHost::ExtensionHost(const Extension* extension,
125 SiteInstance* site_instance, 124 SiteInstance* site_instance,
126 const GURL& url, 125 const GURL& url,
127 ViewType::Type host_type) 126 ViewType::Type host_type)
128 : extension_(extension), 127 : extension_(extension),
128 id_(extension->id()),
129 profile_(site_instance->browsing_instance()->profile()), 129 profile_(site_instance->browsing_instance()->profile()),
130 did_stop_loading_(false), 130 did_stop_loading_(false),
131 document_element_available_(false), 131 document_element_available_(false),
132 url_(url), 132 url_(url),
133 extension_host_type_(host_type), 133 extension_host_type_(host_type),
134 associated_tab_contents_(NULL), 134 associated_tab_contents_(NULL),
135 suppress_javascript_messages_(false) { 135 suppress_javascript_messages_(false) {
136 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE, 136 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE,
137 NULL); 137 NULL);
138 render_view_host_->set_is_extension_process(true); 138 render_view_host_->set_is_extension_process(true);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 227 }
228 228
229 gfx::NativeView ExtensionHost::GetNativeViewOfHost() { 229 gfx::NativeView ExtensionHost::GetNativeViewOfHost() {
230 return view() ? view()->native_view() : NULL; 230 return view() ? view()->native_view() : NULL;
231 } 231 }
232 232
233 void ExtensionHost::NavigateToURL(const GURL& url) { 233 void ExtensionHost::NavigateToURL(const GURL& url) {
234 // Prevent explicit navigation to another extension id's pages. 234 // Prevent explicit navigation to another extension id's pages.
235 // This method is only called by some APIs, so we still need to protect 235 // This method is only called by some APIs, so we still need to protect
236 // DidNavigate below (location = ""). 236 // DidNavigate below (location = "").
237 if (url.SchemeIs(chrome::kExtensionScheme) && 237 if (url.SchemeIs(chrome::kExtensionScheme) && url.host() != id()) {
238 url.host() != extension_->id()) {
239 // TODO(erikkay) communicate this back to the caller? 238 // TODO(erikkay) communicate this back to the caller?
240 return; 239 return;
241 } 240 }
242 241
243 url_ = url; 242 url_ = url;
244 243
245 if (!is_background_page() && 244 if (!is_background_page() &&
246 !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) { 245 !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) {
247 // Make sure the background page loads before any others. 246 // Make sure the background page loads before any others.
248 registrar_.Add(this, NotificationType::EXTENSION_BACKGROUND_PAGE_READY, 247 registrar_.Add(this, NotificationType::EXTENSION_BACKGROUND_PAGE_READY,
249 Source<Extension>(extension_)); 248 Source<Extension>(extension_));
250 return; 249 return;
251 } 250 }
252 251
253 render_view_host_->NavigateToURL(url_); 252 render_view_host_->NavigateToURL(url_);
254 } 253 }
255 254
256 void ExtensionHost::Observe(NotificationType type, 255 void ExtensionHost::Observe(NotificationType type,
257 const NotificationSource& source, 256 const NotificationSource& source,
258 const NotificationDetails& details) { 257 const NotificationDetails& details) {
259 switch (type.value) { 258 switch (type.value) {
260 case NotificationType::EXTENSION_BACKGROUND_PAGE_READY: 259 case NotificationType::EXTENSION_BACKGROUND_PAGE_READY:
261 DCHECK(profile_->GetExtensionService()-> 260 DCHECK(profile_->GetExtensionService()->
262 IsBackgroundPageReady(extension_)); 261 IsBackgroundPageReady(extension_));
263 NavigateToURL(url_); 262 NavigateToURL(url_);
264 break; 263 break;
265 case NotificationType::RENDERER_PROCESS_CREATED: 264 case NotificationType::RENDERER_PROCESS_CREATED:
266 NotificationService::current()->Notify( 265 NotificationService::current()->Notify(
267 NotificationType::EXTENSION_PROCESS_CREATED, 266 NotificationType::EXTENSION_PROCESS_CREATED,
268 Source<Profile>(profile_), 267 Source<Profile>(profile_),
269 Details<ExtensionHost>(this)); 268 Details<ExtensionHost>(this));
270 break; 269 break;
271 case NotificationType::EXTENSION_UNLOADED: 270 case NotificationType::EXTENSION_UNLOADED:
272 // The extension object will be deleted after this notification has been 271 // The extension object will be deleted after this notification has been
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 334
336 // This catches two bogus use cases: 335 // This catches two bogus use cases:
337 // (1) URLs that look like chrome-extension://somethingbogus or 336 // (1) URLs that look like chrome-extension://somethingbogus or
338 // chrome-extension://nosuchid/, in other words, no Extension would 337 // chrome-extension://nosuchid/, in other words, no Extension would
339 // be found. 338 // be found.
340 // (2) URLs that refer to a different extension than this one. 339 // (2) URLs that refer to a different extension than this one.
341 // In both cases, we preserve the old URL and reset the EFD to NULL. This 340 // In both cases, we preserve the old URL and reset the EFD to NULL. This
342 // will leave the host in kind of a bad state with poor UI and errors, but 341 // will leave the host in kind of a bad state with poor UI and errors, but
343 // it's better than the alternative. 342 // it's better than the alternative.
344 // TODO(erikkay) Perhaps we should display errors in developer mode. 343 // TODO(erikkay) Perhaps we should display errors in developer mode.
345 if (params.url.host() != extension_->id()) { 344 if (params.url.host() != id()) {
346 extension_function_dispatcher_.reset(NULL); 345 extension_function_dispatcher_.reset(NULL);
347 return; 346 return;
348 } 347 }
349 348
350 url_ = params.url; 349 url_ = params.url;
351 extension_function_dispatcher_.reset( 350 extension_function_dispatcher_.reset(
352 ExtensionFunctionDispatcher::Create(render_view_host_, this, url_)); 351 ExtensionFunctionDispatcher::Create(render_view_host_, this, url_));
353 } 352 }
354 353
355 void ExtensionHost::InsertInfobarCSS() { 354 void ExtensionHost::InsertInfobarCSS() {
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 return window_id; 826 return window_id;
828 } 827 }
829 828
830 void ExtensionHost::OnRunFileChooser( 829 void ExtensionHost::OnRunFileChooser(
831 const ViewHostMsg_RunFileChooser_Params& params) { 830 const ViewHostMsg_RunFileChooser_Params& params) {
832 if (file_select_helper_.get() == NULL) 831 if (file_select_helper_.get() == NULL)
833 file_select_helper_.reset(new FileSelectHelper(profile())); 832 file_select_helper_.reset(new FileSelectHelper(profile()));
834 file_select_helper_->RunFileChooser(render_view_host_, 833 file_select_helper_->RunFileChooser(render_view_host_,
835 associated_tab_contents(), params); 834 associated_tab_contents(), params);
836 } 835 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698