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

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

Issue 159067: Add API: getBackgroundPageView and getToolstripViews (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 4 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/gfx/jpeg_codec.h" 7 #include "base/gfx/jpeg_codec.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/browser_list.h" 10 #include "chrome/browser/browser_list.h"
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 void DetectTabLanguageFunction::Observe(NotificationType type, 759 void DetectTabLanguageFunction::Observe(NotificationType type,
760 const NotificationSource& source, 760 const NotificationSource& source,
761 const NotificationDetails& details) { 761 const NotificationDetails& details) {
762 DCHECK(type == NotificationType::TAB_LANGUAGE_DETERMINED); 762 DCHECK(type == NotificationType::TAB_LANGUAGE_DETERMINED);
763 std::string language(*Details<std::string>(details).ptr()); 763 std::string language(*Details<std::string>(details).ptr());
764 result_.reset(Value::CreateStringValue(language.c_str())); 764 result_.reset(Value::CreateStringValue(language.c_str()));
765 SendResponse(true); 765 SendResponse(true);
766 Release(); // balanced in Run() 766 Release(); // balanced in Run()
767 } 767 }
768 768
769 bool ExecuteScriptWithUrlFunction::RunImpl() {
770 if (args_->IsType(Value::TYPE_NULL))
771 return false;
772 std::string url_string;
773 EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&url_string));
774 scoped_ptr<GURL> url(new GURL(url_string));
775 if (!url->is_valid()) {
776 // The path as passed in is not valid. Try converting to absolute path.
777 *url = AbsolutePath(profile(), extension_id(), url_string);
778 if (!url->is_valid()) {
779 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kInvalidUrlError,
780 url_string);
781 return false;
782 }
783 }
784
785 // Check whether host of the URL is same with the extension.
786 if (url->host() != extension_id()) {
787 error_ = ExtensionErrorUtils::FormatErrorMessage(keys::kInvalidUrlError,
788 url_string);
789 return false;
790 }
791 script_fetcher_.reset(URLFetcher::Create(1, *url, URLFetcher::GET, this));
792 script_fetcher_->set_request_context(Profile::GetDefaultRequestContext());
793 script_fetcher_->Start();
794
795 AddRef(); // balanced in OnURLFetchComplete()
796 return true;
797 }
798
799 void ExecuteScriptWithUrlFunction::OnURLFetchComplete(
800 const URLFetcher* source, const GURL& url,
801 const URLRequestStatus& status, int response_code,
802 const ResponseCookies& cookies, const std::string& data) {
803 result_.reset(Value::CreateStringValue(data.c_str()));
804 SendResponse(true);
805 Release(); // balanced in OnURLFetchComplete()
806 }
807
769 // static helpers 808 // static helpers
770 809
771 // if |populate| is true, each window gets a list property |tabs| which contains 810 // if |populate| is true, each window gets a list property |tabs| which contains
772 // fully populated tab objects. 811 // fully populated tab objects.
773 static DictionaryValue* CreateWindowValue(Browser* browser, 812 static DictionaryValue* CreateWindowValue(Browser* browser,
774 bool populate_tabs) { 813 bool populate_tabs) {
775 DictionaryValue* result = new DictionaryValue(); 814 DictionaryValue* result = new DictionaryValue();
776 result->SetInteger(keys::kIdKey, ExtensionTabUtil::GetWindowId( 815 result->SetInteger(keys::kIdKey, ExtensionTabUtil::GetWindowId(
777 browser)); 816 browser));
778 result->SetBoolean(keys::kFocusedKey, 817 result->SetBoolean(keys::kFocusedKey,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 if (ExtensionTabUtil::GetTabById(tab_id, profile, browser, tab_strip, 874 if (ExtensionTabUtil::GetTabById(tab_id, profile, browser, tab_strip,
836 contents, tab_index)) 875 contents, tab_index))
837 return true; 876 return true;
838 877
839 if (error_message) 878 if (error_message)
840 *error_message = ExtensionErrorUtils::FormatErrorMessage( 879 *error_message = ExtensionErrorUtils::FormatErrorMessage(
841 keys::kTabNotFoundError, IntToString(tab_id)); 880 keys::kTabNotFoundError, IntToString(tab_id));
842 881
843 return false; 882 return false;
844 } 883 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_tabs_module.h ('k') | chrome/browser/extensions/extension_tabs_module_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698