diff options
Diffstat (limited to 'chrome/browser/extensions/extension_infobar_module.cc')
-rw-r--r-- | chrome/browser/extensions/extension_infobar_module.cc | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_infobar_module.cc b/chrome/browser/extensions/extension_infobar_module.cc new file mode 100644 index 0000000..491b278 --- /dev/null +++ b/chrome/browser/extensions/extension_infobar_module.cc @@ -0,0 +1,61 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/extensions/extension_infobar_module.h" + +#include "app/l10n_util.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/extensions/extension_infobar_module_constants.h" +#include "chrome/browser/extensions/extension_infobar_delegate.h" +#include "chrome/browser/extensions/extension_tabs_module.h" +#include "chrome/browser/extensions/extension_tabs_module_constants.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/url_constants.h" +#include "grit/generated_resources.h" + +namespace keys = extension_infobar_module_constants; + +bool ShowInfoBarFunction::RunImpl() { + EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); + const DictionaryValue* args = args_as_dictionary(); + + std::string html_path; + EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kHtmlPath, &html_path)); + + GURL url = GURL(std::string(chrome::kExtensionScheme) + + chrome::kStandardSchemeSeparator + + extension_id() + "/" + html_path); + + Browser* browser = dispatcher()->GetBrowser(true); + if (!browser) { + error_ = keys::kNoCurrentWindowError; + return false; + } + + TabContents* tab_contents = NULL; + if (args->HasKey(keys::kTabId)) { + int tab_id = -1; + EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabId, &tab_id)); + + EXTENSION_FUNCTION_VALIDATE(ExtensionTabUtil::GetTabById( + tab_id, browser->profile(), false, // No incognito. + NULL, NULL, &tab_contents, NULL)); + } else { + tab_contents = browser->GetSelectedTabContents(); + } + + if (!tab_contents) { + error_ = keys::kTabNotFoundError; + return false; + } + + tab_contents->AddInfoBar( + new ExtensionInfoBarDelegate(browser, tab_contents, GetExtension(), url)); + + // TODO(finnur): Return the actual DOMWindow object. Bug 26463. + result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); + + return true; +} |