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

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

Issue 7064052: Revert 88142 to fix sync_integration_tests offline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
139 } // namespace 126 } // namespace
140 127
141 int ExtensionTabUtil::GetWindowId(const Browser* browser) { 128 int ExtensionTabUtil::GetWindowId(const Browser* browser) {
142 return browser->session_id().id(); 129 return browser->session_id().id();
143 } 130 }
144 131
145 int ExtensionTabUtil::GetTabId(const TabContents* tab_contents) { 132 int ExtensionTabUtil::GetTabId(const TabContents* tab_contents) {
146 return tab_contents->controller().session_id().id(); 133 return tab_contents->controller().session_id().id();
147 } 134 }
148 135
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 395
409 // Second, resolve, validate and convert them to GURLs. 396 // Second, resolve, validate and convert them to GURLs.
410 for (std::vector<std::string>::iterator i = url_strings.begin(); 397 for (std::vector<std::string>::iterator i = url_strings.begin();
411 i != url_strings.end(); ++i) { 398 i != url_strings.end(); ++i) {
412 GURL url = ResolvePossiblyRelativeURL(*i, GetExtension()); 399 GURL url = ResolvePossiblyRelativeURL(*i, GetExtension());
413 if (!url.is_valid()) { 400 if (!url.is_valid()) {
414 error_ = ExtensionErrorUtils::FormatErrorMessage( 401 error_ = ExtensionErrorUtils::FormatErrorMessage(
415 keys::kInvalidUrlError, *i); 402 keys::kInvalidUrlError, *i);
416 return false; 403 return false;
417 } 404 }
418 // Don't let the extension crash the browser or renderers.
419 if (IsCrashURL(url)) {
420 error_ = keys::kNoCrashBrowserError;
421 return false;
422 }
423 urls.push_back(url); 405 urls.push_back(url);
424 } 406 }
425 } 407 }
426 } 408 }
427 409
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
428 // Look for optional tab id. 419 // Look for optional tab id.
429 if (args) { 420 if (args) {
430 int tab_id; 421 int tab_id;
431 if (args->HasKey(keys::kTabIdKey)) { 422 if (args->HasKey(keys::kTabIdKey)) {
432 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabIdKey, &tab_id)); 423 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabIdKey, &tab_id));
433 424
434 // Find the tab and detach it from the original window. 425 // Find the tab and detach it from the original window.
435 Browser* source_browser = NULL; 426 Browser* source_browser = NULL;
436 TabStripModel* source_tab_strip = NULL; 427 TabStripModel* source_tab_strip = NULL;
437 int tab_index = -1; 428 int tab_index = -1;
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 &url_string)); 739 &url_string));
749 url = ResolvePossiblyRelativeURL(url_string, GetExtension()); 740 url = ResolvePossiblyRelativeURL(url_string, GetExtension());
750 if (!url.is_valid()) { 741 if (!url.is_valid()) {
751 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, 742 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kInvalidUrlError,
752 url_string); 743 url_string);
753 return false; 744 return false;
754 } 745 }
755 } 746 }
756 747
757 // Don't let extensions crash the browser or renderers. 748 // Don't let extensions crash the browser or renderers.
758 if (IsCrashURL(url)) { 749 if (url == GURL(chrome::kAboutBrowserCrash) ||
750 url == GURL(chrome::kAboutCrashURL)) {
759 error_ = keys::kNoCrashBrowserError; 751 error_ = keys::kNoCrashBrowserError;
760 return false; 752 return false;
761 } 753 }
762 754
763 // Default to foreground for the new tab. The presence of 'selected' property 755 // Default to foreground for the new tab. The presence of 'selected' property
764 // will override this default. 756 // will override this default.
765 bool selected = true; 757 bool selected = true;
766 if (args->HasKey(keys::kSelectedKey)) 758 if (args->HasKey(keys::kSelectedKey))
767 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kSelectedKey, 759 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kSelectedKey,
768 &selected)); 760 &selected));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 if (!GetTabById(tab_id, profile(), include_incognito(), 856 if (!GetTabById(tab_id, profile(), include_incognito(),
865 NULL, &tab_strip, &contents, &tab_index, &error_)) 857 NULL, &tab_strip, &contents, &tab_index, &error_))
866 return false; 858 return false;
867 859
868 NavigationController& controller = contents->controller(); 860 NavigationController& controller = contents->controller();
869 861
870 // TODO(rafaelw): handle setting remaining tab properties: 862 // TODO(rafaelw): handle setting remaining tab properties:
871 // -title 863 // -title
872 // -favIconUrl 864 // -favIconUrl
873 865
874 // Navigate the tab to a new location if the url is different. 866 // Navigate the tab to a new location if the url different.
875 std::string url_string; 867 std::string url_string;
876 if (update_props->HasKey(keys::kUrlKey)) { 868 if (update_props->HasKey(keys::kUrlKey)) {
877 EXTENSION_FUNCTION_VALIDATE(update_props->GetString( 869 EXTENSION_FUNCTION_VALIDATE(update_props->GetString(
878 keys::kUrlKey, &url_string)); 870 keys::kUrlKey, &url_string));
879 GURL url = ResolvePossiblyRelativeURL(url_string, GetExtension()); 871 GURL url = ResolvePossiblyRelativeURL(url_string, GetExtension());
880 872
881 if (!url.is_valid()) { 873 if (!url.is_valid()) {
882 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kInvalidUrlError, 874 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kInvalidUrlError,
883 url_string); 875 url_string);
884 return false; 876 return false;
885 } 877 }
886 878
887 // Don't let the extension crash the browser or renderers. 879 // Don't let the extension crash the browser or renderers.
888 if (IsCrashURL(url)) { 880 if (url == GURL(chrome::kAboutBrowserCrash) ||
881 url == GURL(chrome::kAboutCrashURL)) {
889 error_ = keys::kNoCrashBrowserError; 882 error_ = keys::kNoCrashBrowserError;
890 return false; 883 return false;
891 } 884 }
892 885
893 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so 886 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so
894 // we need to check host permissions before allowing them. 887 // we need to check host permissions before allowing them.
895 if (url.SchemeIs(chrome::kJavaScriptScheme)) { 888 if (url.SchemeIs(chrome::kJavaScriptScheme)) {
896 if (!GetExtension()->CanExecuteScriptOnPage( 889 if (!GetExtension()->CanExecuteScriptOnPage(
897 contents->tab_contents()->GetURL(), NULL, &error_)) { 890 contents->tab_contents()->GetURL(), NULL, &error_)) {
898 return false; 891 return false;
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 // called for every API call the extension made. 1343 // called for every API call the extension made.
1351 GotLanguage(language); 1344 GotLanguage(language);
1352 } 1345 }
1353 1346
1354 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { 1347 void DetectTabLanguageFunction::GotLanguage(const std::string& language) {
1355 result_.reset(Value::CreateStringValue(language.c_str())); 1348 result_.reset(Value::CreateStringValue(language.c_str()));
1356 SendResponse(true); 1349 SendResponse(true);
1357 1350
1358 Release(); // Balanced in Run() 1351 Release(); // Balanced in Run()
1359 } 1352 }
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