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

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

Issue 7068007: Revise about: and chrome: url handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update special_tabs.py from Nirnimesh's codereview.chromium.org/6995057/. Created 9 years, 6 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
« no previous file with comments | « chrome/browser/extensions/extension_install_ui.cc ('k') | chrome/browser/history/history.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_tabs_module.h" 5 #include "chrome/browser/extensions/extension_tabs_module.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 std::string GetWindowTypeText(const Browser* browser) { 116 std::string GetWindowTypeText(const Browser* browser) {
117 if (browser->is_type_popup()) 117 if (browser->is_type_popup())
118 return keys::kWindowTypeValuePopup; 118 return keys::kWindowTypeValuePopup;
119 if (browser->is_type_panel()) 119 if (browser->is_type_panel())
120 return keys::kWindowTypeValuePanel; 120 return keys::kWindowTypeValuePanel;
121 if (browser->is_app()) 121 if (browser->is_app())
122 return keys::kWindowTypeValueApp; 122 return keys::kWindowTypeValueApp;
123 return keys::kWindowTypeValueNormal; 123 return keys::kWindowTypeValueNormal;
124 } 124 }
125 125
126 bool IsCrashURL(const GURL& url) {
127 // GURL does not parse about: URL hosts, so compare against these entire URLs.
128 if (url == GURL(chrome::kAboutBrowserCrash) ||
129 url == GURL(chrome::kAboutCrashURL))
130 return true;
131
132 // Catch any crash-like URL here.
133 return ((url.SchemeIs(chrome::kAboutScheme) ||
134 url.SchemeIs(chrome::kChromeUIScheme)) &&
135 (url.host() == chrome::kChromeUIBrowserCrashHost ||
136 url.host() == chrome::kChromeUICrashHost));
137 }
138
126 } // namespace 139 } // namespace
127 140
128 int ExtensionTabUtil::GetWindowId(const Browser* browser) { 141 int ExtensionTabUtil::GetWindowId(const Browser* browser) {
129 return browser->session_id().id(); 142 return browser->session_id().id();
130 } 143 }
131 144
132 int ExtensionTabUtil::GetTabId(const TabContents* tab_contents) { 145 int ExtensionTabUtil::GetTabId(const TabContents* tab_contents) {
133 return tab_contents->controller().session_id().id(); 146 return tab_contents->controller().session_id().id();
134 } 147 }
135 148
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 408
396 // Second, resolve, validate and convert them to GURLs. 409 // Second, resolve, validate and convert them to GURLs.
397 for (std::vector<std::string>::iterator i = url_strings.begin(); 410 for (std::vector<std::string>::iterator i = url_strings.begin();
398 i != url_strings.end(); ++i) { 411 i != url_strings.end(); ++i) {
399 GURL url = ResolvePossiblyRelativeURL(*i, GetExtension()); 412 GURL url = ResolvePossiblyRelativeURL(*i, GetExtension());
400 if (!url.is_valid()) { 413 if (!url.is_valid()) {
401 error_ = ExtensionErrorUtils::FormatErrorMessage( 414 error_ = ExtensionErrorUtils::FormatErrorMessage(
402 keys::kInvalidUrlError, *i); 415 keys::kInvalidUrlError, *i);
403 return false; 416 return false;
404 } 417 }
418 // Don't let the extension crash the browser or renderers.
419 if (IsCrashURL(url)) {
420 error_ = keys::kNoCrashBrowserError;
421 return false;
422 }
405 urls.push_back(url); 423 urls.push_back(url);
406 } 424 }
407 } 425 }
408 } 426 }
409 427
410 // Don't let the extension crash the browser or renderers.
411 GURL browser_crash(chrome::kAboutBrowserCrash);
412 GURL renderer_crash(chrome::kAboutCrashURL);
413 if (std::find(urls.begin(), urls.end(), browser_crash) != urls.end() ||
414 std::find(urls.begin(), urls.end(), renderer_crash) != urls.end()) {
415 error_ = keys::kNoCrashBrowserError;
416 return false;
417 }
418
419 // Look for optional tab id. 428 // Look for optional tab id.
420 if (args) { 429 if (args) {
421 int tab_id; 430 int tab_id;
422 if (args->HasKey(keys::kTabIdKey)) { 431 if (args->HasKey(keys::kTabIdKey)) {
423 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabIdKey, &tab_id)); 432 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabIdKey, &tab_id));
424 433
425 // Find the tab and detach it from the original window. 434 // Find the tab and detach it from the original window.
426 Browser* source_browser = NULL; 435 Browser* source_browser = NULL;
427 TabStripModel* source_tab_strip = NULL; 436 TabStripModel* source_tab_strip = NULL;
428 int tab_index = -1; 437 int tab_index = -1;
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 &url_string)); 748 &url_string));
740 url = ResolvePossiblyRelativeURL(url_string, GetExtension()); 749 url = ResolvePossiblyRelativeURL(url_string, GetExtension());
741 if (!url.is_valid()) { 750 if (!url.is_valid()) {
742 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, 751 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kInvalidUrlError,
743 url_string); 752 url_string);
744 return false; 753 return false;
745 } 754 }
746 } 755 }
747 756
748 // Don't let extensions crash the browser or renderers. 757 // Don't let extensions crash the browser or renderers.
749 if (url == GURL(chrome::kAboutBrowserCrash) || 758 if (IsCrashURL(url)) {
750 url == GURL(chrome::kAboutCrashURL)) {
751 error_ = keys::kNoCrashBrowserError; 759 error_ = keys::kNoCrashBrowserError;
752 return false; 760 return false;
753 } 761 }
754 762
755 // Default to foreground for the new tab. The presence of 'selected' property 763 // Default to foreground for the new tab. The presence of 'selected' property
756 // will override this default. 764 // will override this default.
757 bool selected = true; 765 bool selected = true;
758 if (args->HasKey(keys::kSelectedKey)) 766 if (args->HasKey(keys::kSelectedKey))
759 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kSelectedKey, 767 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kSelectedKey,
760 &selected)); 768 &selected));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 if (!GetTabById(tab_id, profile(), include_incognito(), 864 if (!GetTabById(tab_id, profile(), include_incognito(),
857 NULL, &tab_strip, &contents, &tab_index, &error_)) 865 NULL, &tab_strip, &contents, &tab_index, &error_))
858 return false; 866 return false;
859 867
860 NavigationController& controller = contents->controller(); 868 NavigationController& controller = contents->controller();
861 869
862 // TODO(rafaelw): handle setting remaining tab properties: 870 // TODO(rafaelw): handle setting remaining tab properties:
863 // -title 871 // -title
864 // -favIconUrl 872 // -favIconUrl
865 873
866 // Navigate the tab to a new location if the url different. 874 // Navigate the tab to a new location if the url is different.
867 std::string url_string; 875 std::string url_string;
868 if (update_props->HasKey(keys::kUrlKey)) { 876 if (update_props->HasKey(keys::kUrlKey)) {
869 EXTENSION_FUNCTION_VALIDATE(update_props->GetString( 877 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(
870 keys::kUrlKey, &url_string)); 878 keys::kUrlKey, &url_string));
871 GURL url = ResolvePossiblyRelativeURL(url_string, GetExtension()); 879 GURL url = ResolvePossiblyRelativeURL(url_string, GetExtension());
872 880
873 if (!url.is_valid()) { 881 if (!url.is_valid()) {
874 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, 882 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kInvalidUrlError,
875 url_string); 883 url_string);
876 return false; 884 return false;
877 } 885 }
878 886
879 // Don't let the extension crash the browser or renderers. 887 // Don't let the extension crash the browser or renderers.
880 if (url == GURL(chrome::kAboutBrowserCrash) || 888 if (IsCrashURL(url)) {
881 url == GURL(chrome::kAboutCrashURL)) {
882 error_ = keys::kNoCrashBrowserError; 889 error_ = keys::kNoCrashBrowserError;
883 return false; 890 return false;
884 } 891 }
885 892
886 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so 893 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so
887 // we need to check host permissions before allowing them. 894 // we need to check host permissions before allowing them.
888 if (url.SchemeIs(chrome::kJavaScriptScheme)) { 895 if (url.SchemeIs(chrome::kJavaScriptScheme)) {
889 if (!GetExtension()->CanExecuteScriptOnPage( 896 if (!GetExtension()->CanExecuteScriptOnPage(
890 contents->tab_contents()->GetURL(), NULL, &error_)) { 897 contents->tab_contents()->GetURL(), NULL, &error_)) {
891 return false; 898 return false;
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 // called for every API call the extension made. 1350 // called for every API call the extension made.
1344 GotLanguage(language); 1351 GotLanguage(language);
1345 } 1352 }
1346 1353
1347 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1354 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1348 result_.reset(Value::CreateStringValue(language.c_str())); 1355 result_.reset(Value::CreateStringValue(language.c_str()));
1349 SendResponse(true); 1356 SendResponse(true);
1350 1357
1351 Release(); // Balanced in Run() 1358 Release(); // Balanced in Run()
1352 } 1359 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_install_ui.cc ('k') | chrome/browser/history/history.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698