| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/infobars/infobar_extension_api.h" | |
| 6 | |
| 7 #include "base/strings/string_number_conversions.h" | |
| 8 #include "base/strings/string_util.h" | |
| 9 #include "base/values.h" | |
| 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | |
| 11 #include "chrome/browser/extensions/extension_infobar_delegate.h" | |
| 12 #include "chrome/browser/extensions/extension_tab_util.h" | |
| 13 #include "chrome/browser/extensions/window_controller.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | |
| 15 #include "chrome/browser/ui/browser.h" | |
| 16 #include "chrome/common/url_constants.h" | |
| 17 #include "content/public/browser/web_contents.h" | |
| 18 #include "extensions/browser/extension_host.h" | |
| 19 #include "extensions/common/error_utils.h" | |
| 20 #include "extensions/common/extension.h" | |
| 21 | |
| 22 bool InfobarsShowFunction::RunSync() { | |
| 23 base::DictionaryValue* args; | |
| 24 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | |
| 25 | |
| 26 const char kTabId[] = "tabId"; | |
| 27 int tab_id; | |
| 28 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(kTabId, &tab_id)); | |
| 29 | |
| 30 const char kHtmlPath[] = "path"; | |
| 31 std::string html_path; | |
| 32 EXTENSION_FUNCTION_VALIDATE(args->GetString(kHtmlPath, &html_path)); | |
| 33 | |
| 34 const char kHeight[] = "height"; | |
| 35 int height = 0; | |
| 36 if (args->HasKey(kHeight)) | |
| 37 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(kHeight, &height)); | |
| 38 | |
| 39 Browser* browser = NULL; | |
| 40 content::WebContents* web_contents = NULL; | |
| 41 if (!extensions::ExtensionTabUtil::GetTabById(tab_id, GetProfile(), | |
| 42 include_incognito(), &browser, | |
| 43 NULL, &web_contents, NULL)) { | |
| 44 error_ = extensions::ErrorUtils::FormatErrorMessage( | |
| 45 extensions::tabs_constants::kTabNotFoundError, | |
| 46 base::IntToString(tab_id)); | |
| 47 return false; | |
| 48 } | |
| 49 GURL url(extension()->GetResourceURL(extension()->url(), html_path)); | |
| 50 ExtensionInfoBarDelegate::Create( | |
| 51 web_contents, browser, extension(), url, height); | |
| 52 | |
| 53 // TODO(finnur): Return the actual DOMWindow object. Bug 26463. | |
| 54 DCHECK(browser->extension_window_controller()); | |
| 55 SetResult(browser->extension_window_controller()->CreateWindowValue()); | |
| 56 | |
| 57 return true; | |
| 58 } | |
| OLD | NEW |