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

Side by Side Diff: chrome/browser/infobars/infobar_extension_api.cc

Issue 8374024: Move infobar extension API implementation to infobars dir. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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) 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_infobar_module.h" 5 #include "chrome/browser/infobars/infobar_extension_api.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/extension_host.h" 10 #include "chrome/browser/extensions/extension_host.h"
11 #include "chrome/browser/extensions/extension_infobar_delegate.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_tab_util.h" 12 #include "chrome/browser/extensions/extension_tab_util.h"
14 #include "chrome/browser/extensions/extension_tabs_module_constants.h" 13 #include "chrome/browser/extensions/extension_tabs_module_constants.h"
15 #include "chrome/browser/infobars/infobar_tab_helper.h" 14 #include "chrome/browser/infobars/infobar_tab_helper.h"
16 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 15 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
17 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
19 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_error_utils.h" 19 #include "chrome/common/extensions/extension_error_utils.h"
21 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
22 #include "content/browser/tab_contents/tab_contents.h" 21 #include "content/browser/tab_contents/tab_contents.h"
23 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
24 23
25 namespace keys = extension_infobar_module_constants; 24 namespace {
25
26 const char kHtmlPath[] = "path";
27 const char kTabId[] = "tabId";
28 const char kHeight[] = "height";
29
30 const char kNoCurrentWindowError[] = "No current browser window was found";
31 const char kTabNotFoundError[] = "Specified tab (or default tab) not found";
32
33 } // namespace
26 34
27 bool ShowInfoBarFunction::RunImpl() { 35 bool ShowInfoBarFunction::RunImpl() {
28 DictionaryValue* args; 36 DictionaryValue* args;
29 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 37 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
30 38
31 int tab_id; 39 int tab_id;
32 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kTabId, &tab_id)); 40 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(kTabId, &tab_id));
33 41
34 std::string html_path; 42 std::string html_path;
35 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kHtmlPath, &html_path)); 43 EXTENSION_FUNCTION_VALIDATE(args->GetString(kHtmlPath, &html_path));
36 44
37 int height = 0; 45 int height = 0;
38 if (args->HasKey(keys::kHeight)) 46 if (args->HasKey(kHeight))
39 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeight, &height)); 47 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(kHeight, &height));
40 48
41 const Extension* extension = GetExtension(); 49 const Extension* extension = GetExtension();
42 GURL url = extension->GetResourceURL(extension->url(), html_path); 50 GURL url = extension->GetResourceURL(extension->url(), html_path);
43 51
44 Browser* browser = NULL; 52 Browser* browser = NULL;
45 TabContentsWrapper* tab_contents = NULL; 53 TabContentsWrapper* tab_contents = NULL;
46 if (!ExtensionTabUtil::GetTabById( 54 if (!ExtensionTabUtil::GetTabById(
47 tab_id, 55 tab_id,
48 profile(), 56 profile(),
49 include_incognito(), 57 include_incognito(),
50 &browser, 58 &browser,
51 NULL, 59 NULL,
52 &tab_contents, 60 &tab_contents,
53 NULL)) { 61 NULL)) {
54 error_ = ExtensionErrorUtils::FormatErrorMessage( 62 error_ = ExtensionErrorUtils::FormatErrorMessage(
55 extension_tabs_module_constants::kTabNotFoundError, 63 extension_tabs_module_constants::kTabNotFoundError,
56 base::IntToString(tab_id)); 64 base::IntToString(tab_id));
57 return false; 65 return false;
58 } 66 }
59 67
60 tab_contents->infobar_tab_helper()->AddInfoBar( 68 tab_contents->infobar_tab_helper()->AddInfoBar(
61 new ExtensionInfoBarDelegate(browser, tab_contents->infobar_tab_helper(), 69 new ExtensionInfoBarDelegate(browser, tab_contents->infobar_tab_helper(),
62 GetExtension(), url, height)); 70 GetExtension(), url, height));
63 71
64 // TODO(finnur): Return the actual DOMWindow object. Bug 26463. 72 // TODO(finnur): Return the actual DOMWindow object. Bug 26463.
65 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false)); 73 result_.reset(ExtensionTabUtil::CreateWindowValue(browser, false));
66 74
67 return true; 75 return true;
68 } 76 }
OLDNEW
« no previous file with comments | « chrome/browser/infobars/infobar_extension_api.h ('k') | chrome/browser/infobars/infobar_extension_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698