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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/extensions/extension_infobar_module.h" 6 7 #include "base/string_number_conversions.h" 8 #include "base/string_util.h" 9 #include "base/values.h" 10 #include "chrome/browser/extensions/extension_host.h" 11 #include "chrome/browser/extensions/extension_infobar_delegate.h" 12 #include "chrome/browser/extensions/extension_infobar_module_constants.h" 13 #include "chrome/browser/extensions/extension_tabs_module.h" 14 #include "chrome/browser/extensions/extension_tabs_module_constants.h" 15 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 16 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 18 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension_error_utils.h" 20 #include "chrome/common/url_constants.h" 21 #include "content/browser/tab_contents/tab_contents.h" 22 #include "grit/generated_resources.h" 23 24 namespace keys = extension_infobar_module_constants; 25 26 bool ShowInfoBarFunction::RunImpl() { 27 DictionaryValue* args; 28 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 29 30 int tab_id; 31 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabId, &tab_id)); 32 33 std::string html_path; 34 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kHtmlPath, &html_path)); 35 36 const Extension* extension = GetExtension(); 37 GURL url = extension->GetResourceURL(extension->url(), html_path); 38 39 Browser* browser = NULL; 40 TabContentsWrapper* tab_contents = NULL; 41 if (!ExtensionTabUtil::GetTabById( 42 tab_id, 43 profile(), 44 include_incognito(), 45 &browser, 46 NULL, 47 &tab_contents, 48 NULL)) { 49 error_ = ExtensionErrorUtils::FormatErrorMessage( 50 extension_tabs_module_constants::kTabNotFoundError, 51 base::IntToString(tab_id)); 52 return false; 53 } 54 55 tab_contents->tab_contents()->AddInfoBar( 56 new ExtensionInfoBarDelegate(browser, tab_contents->tab_contents(), 57 GetExtension(), url)); 58 59 // TODO(finnur): Return the actual DOMWindow object. Bug 26463. 60 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); 61 62 return true; 63 } 64