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

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

Issue 133003003: Make ErrorConsole catch errors from Extension WebContents Views (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing license Created 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_contents_observer.h" 5 #include "chrome/browser/extensions/extension_web_contents_observer.h"
6 6
7 #include "chrome/browser/extensions/api/messaging/message_service.h" 7 #include "chrome/browser/extensions/api/messaging/message_service.h"
8 #include "chrome/browser/extensions/error_console/error_console.h"
8 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_system.h" 10 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/common/extensions/api/messaging/message.h" 11 #include "chrome/common/extensions/api/messaging/message.h"
11 #include "chrome/common/extensions/extension_messages.h" 12 #include "chrome/common/extensions/extension_messages.h"
13 #include "chrome/common/render_messages.h"
12 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
13 #include "content/public/browser/child_process_security_policy.h" 15 #include "content/public/browser/child_process_security_policy.h"
14 #include "content/public/browser/render_process_host.h" 16 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/render_view_host.h" 17 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/site_instance.h" 18 #include "content/public/browser/site_instance.h"
17 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
18 #include "extensions/browser/extension_registry.h" 20 #include "extensions/browser/extension_registry.h"
19 #include "extensions/browser/view_type_utils.h" 21 #include "extensions/browser/view_type_utils.h"
20 #include "extensions/common/constants.h" 22 #include "extensions/common/constants.h"
23 #include "extensions/common/extension_urls.h"
21 24
22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::ExtensionWebContentsObserver); 25 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::ExtensionWebContentsObserver);
23 26
24 namespace extensions { 27 namespace extensions {
25 28
26 ExtensionWebContentsObserver::ExtensionWebContentsObserver( 29 ExtensionWebContentsObserver::ExtensionWebContentsObserver(
27 content::WebContents* web_contents) 30 content::WebContents* web_contents)
28 : content::WebContentsObserver(web_contents), 31 : content::WebContentsObserver(web_contents),
29 browser_context_(web_contents->GetBrowserContext()) { 32 browser_context_(web_contents->GetBrowserContext()) {
30 } 33 }
31 34
32 ExtensionWebContentsObserver::~ExtensionWebContentsObserver() { 35 ExtensionWebContentsObserver::~ExtensionWebContentsObserver() {
33 } 36 }
34 37
35 void ExtensionWebContentsObserver::RenderViewCreated( 38 void ExtensionWebContentsObserver::RenderViewCreated(
36 content::RenderViewHost* render_view_host) { 39 content::RenderViewHost* render_view_host) {
37 render_view_host->Send(new ExtensionMsg_NotifyRenderViewType( 40 render_view_host->Send(new ExtensionMsg_NotifyRenderViewType(
38 render_view_host->GetRoutingID(), 41 render_view_host->GetRoutingID(),
39 extensions::GetViewType(web_contents()))); 42 GetViewType(web_contents())));
40 43
41 const Extension* extension = GetExtension(render_view_host); 44 const Extension* extension = GetExtension(render_view_host);
42 if (!extension) 45 if (!extension)
43 return; 46 return;
44 47
45 content::RenderProcessHost* process = render_view_host->GetProcess(); 48 content::RenderProcessHost* process = render_view_host->GetProcess();
46 49
47 // Some extensions use chrome:// URLs. 50 // Some extensions use chrome:// URLs.
48 // This is a temporary solution. Replace it with access to chrome-static:// 51 // This is a temporary solution. Replace it with access to chrome-static://
49 // once it is implemented. See: crbug.com/226927. 52 // once it is implemented. See: crbug.com/226927.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 case Manifest::TYPE_SHARED_MODULE: 91 case Manifest::TYPE_SHARED_MODULE:
89 break; 92 break;
90 } 93 }
91 } 94 }
92 95
93 bool ExtensionWebContentsObserver::OnMessageReceived( 96 bool ExtensionWebContentsObserver::OnMessageReceived(
94 const IPC::Message& message) { 97 const IPC::Message& message) {
95 bool handled = true; 98 bool handled = true;
96 IPC_BEGIN_MESSAGE_MAP(ExtensionWebContentsObserver, message) 99 IPC_BEGIN_MESSAGE_MAP(ExtensionWebContentsObserver, message)
97 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage) 100 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage)
101 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DetailedConsoleMessageAdded,
102 OnDetailedConsoleMessageAdded)
98 IPC_MESSAGE_UNHANDLED(handled = false) 103 IPC_MESSAGE_UNHANDLED(handled = false)
99 IPC_END_MESSAGE_MAP() 104 IPC_END_MESSAGE_MAP()
100 return handled; 105 return handled;
101 } 106 }
102 107
108 void ExtensionWebContentsObserver::OnDetailedConsoleMessageAdded(
109 const base::string16& message,
110 const base::string16& source,
111 const StackTrace& stack_trace,
112 int32 severity_level) {
113 if (IsSourceFromAnExtension(source)) {
114 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
115 ErrorConsole::Get(Profile::FromBrowserContext(browser_context_))->
116 ReportError(
117 scoped_ptr<ExtensionError>(new RuntimeError(
118 std::string(),
119 browser_context_->IsOffTheRecord(),
120 source,
121 message,
122 stack_trace,
123 web_contents() ?
124 web_contents()->GetLastCommittedURL() : GURL::EmptyGURL(),
125 static_cast<logging::LogSeverity>(severity_level),
126 rvh->GetRoutingID(),
127 rvh->GetProcess()->GetID())));
128 }
129 }
130
103 void ExtensionWebContentsObserver::OnPostMessage(int port_id, 131 void ExtensionWebContentsObserver::OnPostMessage(int port_id,
104 const Message& message) { 132 const Message& message) {
105 MessageService* message_service = MessageService::Get(browser_context_); 133 MessageService* message_service = MessageService::Get(browser_context_);
106 if (message_service) { 134 if (message_service) {
107 message_service->PostMessage(port_id, message); 135 message_service->PostMessage(port_id, message);
108 } 136 }
109 } 137 }
110 138
111 const Extension* ExtensionWebContentsObserver::GetExtension( 139 const Extension* ExtensionWebContentsObserver::GetExtension(
112 content::RenderViewHost* render_view_host) { 140 content::RenderViewHost* render_view_host) {
(...skipping 17 matching lines...) Expand all
130 ExtensionSystem::GetForBrowserContext(browser_context_)-> 158 ExtensionSystem::GetForBrowserContext(browser_context_)->
131 extension_service()->ReloadExtension(extension_id); 159 extension_service()->ReloadExtension(extension_id);
132 } 160 }
133 161
134 // May be null if the extension doesn't exist, for example if somebody typos 162 // May be null if the extension doesn't exist, for example if somebody typos
135 // a chrome-extension:// URL. 163 // a chrome-extension:// URL.
136 return registry->enabled_extensions().GetByID(extension_id); 164 return registry->enabled_extensions().GetByID(extension_id);
137 } 165 }
138 166
139 } // namespace extensions 167 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698