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