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

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

Issue 9737001: Fix crash in AppNotifyChannelSetup when incognito profiles are used. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: feedback + test failures Created 8 years, 9 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_tab_helper.h" 5 #include "chrome/browser/extensions/extension_tab_helper.h"
6 6
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/webstore_inline_installer.h" 8 #include "chrome/browser/extensions/webstore_inline_installer.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sessions/restore_tab_helper.h" 10 #include "chrome/browser/sessions/restore_tab_helper.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h" 12 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
14 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/extensions/extension_action.h" 15 #include "chrome/common/extensions/extension_action.h"
16 #include "chrome/common/extensions/extension_constants.h"
16 #include "chrome/common/extensions/extension_icon_set.h" 17 #include "chrome/common/extensions/extension_icon_set.h"
17 #include "chrome/common/extensions/extension_messages.h" 18 #include "chrome/common/extensions/extension_messages.h"
18 #include "chrome/common/extensions/extension_resource.h" 19 #include "chrome/common/extensions/extension_resource.h"
19 #include "content/public/browser/invalidate_type.h" 20 #include "content/public/browser/invalidate_type.h"
20 #include "content/public/browser/navigation_details.h" 21 #include "content/public/browser/navigation_details.h"
21 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/render_widget_host_view.h" 25 #include "content/public/browser/render_widget_host_view.h"
25 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
26 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
27 28
28 using content::WebContents; 29 using content::WebContents;
29 30
31 namespace {
32
33 const char kPermissionError[] = "permission_error";
34
35 } // namespace
36
30 ExtensionTabHelper::ExtensionTabHelper(TabContentsWrapper* wrapper) 37 ExtensionTabHelper::ExtensionTabHelper(TabContentsWrapper* wrapper)
31 : content::WebContentsObserver(wrapper->web_contents()), 38 : content::WebContentsObserver(wrapper->web_contents()),
32 delegate_(NULL), 39 delegate_(NULL),
33 extension_app_(NULL), 40 extension_app_(NULL),
34 ALLOW_THIS_IN_INITIALIZER_LIST( 41 ALLOW_THIS_IN_INITIALIZER_LIST(
35 extension_function_dispatcher_(wrapper->profile(), this)), 42 extension_function_dispatcher_(wrapper->profile(), this)),
36 wrapper_(wrapper) { 43 wrapper_(wrapper) {
37 } 44 }
38 45
39 ExtensionTabHelper::~ExtensionTabHelper() { 46 ExtensionTabHelper::~ExtensionTabHelper() {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 179
173 // Check for permission first. 180 // Check for permission first.
174 Profile* profile = 181 Profile* profile =
175 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 182 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
176 ExtensionService* extension_service = profile->GetExtensionService(); 183 ExtensionService* extension_service = profile->GetExtensionService();
177 extensions::ProcessMap* process_map = extension_service->process_map(); 184 extensions::ProcessMap* process_map = extension_service->process_map();
178 content::RenderProcessHost* process = 185 content::RenderProcessHost* process =
179 tab_contents_wrapper()->web_contents()->GetRenderProcessHost(); 186 tab_contents_wrapper()->web_contents()->GetRenderProcessHost();
180 const Extension* extension = 187 const Extension* extension =
181 extension_service->GetInstalledApp(requestor_url); 188 extension_service->GetInstalledApp(requestor_url);
182 bool allowed = 189
183 extension && 190 std::string error;
184 extension->HasAPIPermission( 191 if (!extension ||
185 ExtensionAPIPermission::kAppNotifications) && 192 !extension->HasAPIPermission(
186 process_map->Contains(extension->id(), process->GetID()); 193 ExtensionAPIPermission::kAppNotifications) ||
187 if (!allowed) { 194 !process_map->Contains(extension->id(), process->GetID()))
195 error = kPermissionError;
196
197 // Make sure the extension can cross to the main profile, if called from an
198 // an incognito window.
199 if (profile->IsOffTheRecord() &&
200 !extension_service->CanCrossIncognito(extension))
201 error = extension_misc::kAppNotificationsIncognitoError;
202
203 if (!error.empty()) {
188 Send(new ExtensionMsg_GetAppNotifyChannelResponse( 204 Send(new ExtensionMsg_GetAppNotifyChannelResponse(
189 return_route_id, "", "permission_error", callback_id)); 205 return_route_id, "", error, callback_id));
190 return; 206 return;
191 } 207 }
192 208
193 AppNotifyChannelUI* ui = new AppNotifyChannelUIImpl( 209 AppNotifyChannelUI* ui = new AppNotifyChannelUIImpl(
194 GetBrowser(), tab_contents_wrapper(), extension->name()); 210 GetBrowser(), tab_contents_wrapper(), extension->name());
195 211
196 scoped_refptr<AppNotifyChannelSetup> channel_setup( 212 scoped_refptr<AppNotifyChannelSetup> channel_setup(
197 new AppNotifyChannelSetup(profile, 213 new AppNotifyChannelSetup(profile,
198 extension->id(), 214 extension->id(),
199 client_id, 215 client_id,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 void ExtensionTabHelper::OnInlineInstallFailure(int install_id, 315 void ExtensionTabHelper::OnInlineInstallFailure(int install_id,
300 int return_route_id, 316 int return_route_id,
301 const std::string& error) { 317 const std::string& error) {
302 Send(new ExtensionMsg_InlineWebstoreInstallResponse( 318 Send(new ExtensionMsg_InlineWebstoreInstallResponse(
303 return_route_id, install_id, false, error)); 319 return_route_id, install_id, false, error));
304 } 320 }
305 321
306 WebContents* ExtensionTabHelper::GetAssociatedWebContents() const { 322 WebContents* ExtensionTabHelper::GetAssociatedWebContents() const {
307 return web_contents(); 323 return web_contents();
308 } 324 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_apitest.cc ('k') | chrome/browser/extensions/extension_tabs_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698