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

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

Issue 2830903003: PS - Scrub URL down to origin in Public Sessions (Closed)
Patch Set: Rebase Created 3 years, 8 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 (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_util.h" 5 #include "chrome/browser/extensions/extension_tab_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // Use this function for reporting a tab id to an extension. It will 108 // Use this function for reporting a tab id to an extension. It will
109 // take care of setting the id to TAB_ID_NONE if necessary (for 109 // take care of setting the id to TAB_ID_NONE if necessary (for
110 // example with devtools). 110 // example with devtools).
111 int GetTabIdForExtensions(const WebContents* web_contents) { 111 int GetTabIdForExtensions(const WebContents* web_contents) {
112 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 112 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
113 if (browser && !ExtensionTabUtil::BrowserSupportsTabs(browser)) 113 if (browser && !ExtensionTabUtil::BrowserSupportsTabs(browser))
114 return -1; 114 return -1;
115 return SessionTabHelper::IdForTab(web_contents); 115 return SessionTabHelper::IdForTab(web_contents);
116 } 116 }
117 117
118 ExtensionTabUtil::Delegate* g_delegate = nullptr;
119
118 } // namespace 120 } // namespace
119 121
120 ExtensionTabUtil::OpenTabParams::OpenTabParams() 122 ExtensionTabUtil::OpenTabParams::OpenTabParams()
121 : create_browser_if_needed(false) { 123 : create_browser_if_needed(false) {
122 } 124 }
123 125
124 ExtensionTabUtil::OpenTabParams::~OpenTabParams() { 126 ExtensionTabUtil::OpenTabParams::~OpenTabParams() {
125 } 127 }
126 128
127 // Opens a new tab for a given extension. Returns NULL and sets |error| if an 129 // Opens a new tab for a given extension. Returns NULL and sets |error| if an
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 case TabMutedReason::EXTENSION: 444 case TabMutedReason::EXTENSION:
443 info->reason = api::tabs::MUTED_INFO_REASON_EXTENSION; 445 info->reason = api::tabs::MUTED_INFO_REASON_EXTENSION;
444 info->extension_id.reset( 446 info->extension_id.reset(
445 new std::string(chrome::GetExtensionIdForMutedTab(contents))); 447 new std::string(chrome::GetExtensionIdForMutedTab(contents)));
446 break; 448 break;
447 } 449 }
448 return info; 450 return info;
449 } 451 }
450 452
451 // static 453 // static
454 void ExtensionTabUtil::SetPlatformDelegate(Delegate* delegate) {
455 // Allow setting it only once (also allow reset to nullptr, but then take
456 // special care to free it).
457 CHECK(!g_delegate || !delegate);
458 g_delegate = delegate;
459 }
460
461 // static
452 void ExtensionTabUtil::ScrubTabForExtension(const Extension* extension, 462 void ExtensionTabUtil::ScrubTabForExtension(const Extension* extension,
453 content::WebContents* contents, 463 content::WebContents* contents,
454 api::tabs::Tab* tab) { 464 api::tabs::Tab* tab) {
455 bool has_permission = false; 465 bool has_permission = false;
456 if (extension) { 466 if (extension) {
457 bool api_permission = false; 467 bool api_permission = false;
458 std::string url; 468 std::string url;
459 if (contents) { 469 if (contents) {
460 api_permission = extension->permissions_data()->HasAPIPermissionForTab( 470 api_permission = extension->permissions_data()->HasAPIPermissionForTab(
461 GetTabId(contents), APIPermission::kTab); 471 GetTabId(contents), APIPermission::kTab);
462 url = contents->GetURL().spec(); 472 url = contents->GetURL().spec();
463 } else { 473 } else {
464 api_permission = 474 api_permission =
465 extension->permissions_data()->HasAPIPermission(APIPermission::kTab); 475 extension->permissions_data()->HasAPIPermission(APIPermission::kTab);
466 url = *tab->url; 476 url = *tab->url;
467 } 477 }
468 bool host_permission = extension->permissions_data() 478 bool host_permission = extension->permissions_data()
469 ->active_permissions() 479 ->active_permissions()
470 .HasExplicitAccessToOrigin(GURL(url)); 480 .HasExplicitAccessToOrigin(GURL(url));
471 has_permission = api_permission || host_permission; 481 has_permission = api_permission || host_permission;
472 } 482 }
473 if (!has_permission) { 483 if (!has_permission) {
474 tab->url.reset(); 484 tab->url.reset();
475 tab->title.reset(); 485 tab->title.reset();
476 tab->fav_icon_url.reset(); 486 tab->fav_icon_url.reset();
477 } 487 }
488 if (g_delegate)
489 g_delegate->ScrubTabForExtension(extension, contents, tab);
478 } 490 }
479 491
480 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents, 492 bool ExtensionTabUtil::GetTabStripModel(const WebContents* web_contents,
481 TabStripModel** tab_strip_model, 493 TabStripModel** tab_strip_model,
482 int* tab_index) { 494 int* tab_index) {
483 DCHECK(web_contents); 495 DCHECK(web_contents);
484 DCHECK(tab_strip_model); 496 DCHECK(tab_strip_model);
485 DCHECK(tab_index); 497 DCHECK(tab_index);
486 498
487 for (auto* browser : *BrowserList::GetInstance()) { 499 for (auto* browser : *BrowserList::GetInstance()) {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 chrome::ShowSingletonTabOverwritingNTP(browser, params); 712 chrome::ShowSingletonTabOverwritingNTP(browser, params);
701 return true; 713 return true;
702 } 714 }
703 715
704 // static 716 // static
705 bool ExtensionTabUtil::BrowserSupportsTabs(Browser* browser) { 717 bool ExtensionTabUtil::BrowserSupportsTabs(Browser* browser) {
706 return browser && browser->tab_strip_model() && !browser->is_devtools(); 718 return browser && browser->tab_strip_model() && !browser->is_devtools();
707 } 719 }
708 720
709 } // namespace extensions 721 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698