Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / infobars / infobar_extension_api.cc
blobfe6d5786577d5ab2b86c443ffaf81fae2e621991
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/infobars/infobar_extension_api.h"
7 #include "base/string_number_conversions.h"
8 #include "base/string_util.h"
9 #include "base/values.h"
10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
12 #include "chrome/browser/extensions/extension_host.h"
13 #include "chrome/browser/extensions/extension_infobar_delegate.h"
14 #include "chrome/browser/extensions/extension_tab_util.h"
15 #include "chrome/browser/extensions/window_controller.h"
16 #include "chrome/browser/infobars/infobar_tab_helper.h"
17 #include "chrome/browser/ui/browser.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/public/browser/web_contents.h"
22 #include "grit/generated_resources.h"
24 using extensions::Extension;
26 namespace {
28 const char kHtmlPath[] = "path";
29 const char kTabId[] = "tabId";
30 const char kHeight[] = "height";
32 const char kNoCurrentWindowError[] = "No current browser window was found";
33 const char kTabNotFoundError[] = "Specified tab (or default tab) not found";
35 } // namespace
37 bool ShowInfoBarFunction::RunImpl() {
38 DictionaryValue* args;
39 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
41 int tab_id;
42 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(kTabId, &tab_id));
44 std::string html_path;
45 EXTENSION_FUNCTION_VALIDATE(args->GetString(kHtmlPath, &html_path));
47 int height = 0;
48 if (args->HasKey(kHeight))
49 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(kHeight, &height));
51 const Extension* extension = GetExtension();
52 GURL url = extension->GetResourceURL(extension->url(), html_path);
54 Browser* browser = NULL;
55 content::WebContents* web_contents = NULL;
56 if (!ExtensionTabUtil::GetTabById(
57 tab_id,
58 profile(),
59 include_incognito(),
60 &browser,
61 NULL,
62 &web_contents,
63 NULL)) {
64 error_ = ExtensionErrorUtils::FormatErrorMessage(
65 extensions::tabs_constants::kTabNotFoundError,
66 base::IntToString(tab_id));
67 return false;
70 InfoBarTabHelper* infobar_tab_helper =
71 InfoBarTabHelper::FromWebContents(web_contents);
72 infobar_tab_helper->AddInfoBar(
73 new ExtensionInfoBarDelegate(browser, infobar_tab_helper,
74 GetExtension(), url, height));
76 // TODO(finnur): Return the actual DOMWindow object. Bug 26463.
77 DCHECK(browser->extension_window_controller());
78 SetResult(browser->extension_window_controller()->CreateWindowValue());
80 return true;