|
7 | 7 | #include "content/public/browser/render_widget_host.h"
|
8 | 8 | #include "chrome/browser/devtools/devtools_window.h"
|
9 | 9 | #include "chrome/browser/extensions/devtools_util.h"
|
| 10 | +#include "chrome/browser/extensions/extension_tab_util.h" |
| 11 | +#include "chrome/browser/extensions/window_controller.h" |
| 12 | +#include "chrome/browser/extensions/api/tabs/windows_util.h" |
| 13 | +#include "chrome/browser/ui/browser.h" |
10 | 14 | #include "components/zoom/zoom_controller.h"
|
11 | 15 | #include "content/nw/src/api/menu/menu.h"
|
12 | 16 | #include "content/nw/src/api/object_manager.h"
|
@@ -102,11 +106,41 @@ printing::PrinterList EnumeratePrintersAsync() {
|
102 | 106 | }
|
103 | 107 |
|
104 | 108 | namespace extensions {
|
| 109 | + |
| 110 | +namespace windows = api::windows; |
| 111 | +namespace tabs = api::tabs; |
| 112 | + |
| 113 | +using api::extension_types::InjectDetails; |
| 114 | + |
105 | 115 | namespace {
|
106 | 116 |
|
107 | 117 | const char kNoAssociatedAppWindow[] =
|
108 | 118 | "The context from which the function was called did not have an "
|
109 | 119 | "associated app window.";
|
| 120 | + |
| 121 | +template <typename T> |
| 122 | +class ApiParameterExtractor { |
| 123 | + public: |
| 124 | + explicit ApiParameterExtractor(T* params) : params_(params) {} |
| 125 | + ~ApiParameterExtractor() {} |
| 126 | + |
| 127 | + bool populate_tabs() { |
| 128 | + if (params_->get_info.get() && params_->get_info->populate.get()) |
| 129 | + return *params_->get_info->populate; |
| 130 | + return false; |
| 131 | + } |
| 132 | + |
| 133 | + WindowController::TypeFilter type_filters() { |
| 134 | + if (params_->get_info.get() && params_->get_info->window_types.get()) |
| 135 | + return WindowController::GetFilterFromWindowTypes( |
| 136 | + *params_->get_info->window_types); |
| 137 | + return WindowController::kNoWindowFilter; |
| 138 | + } |
| 139 | + |
| 140 | + private: |
| 141 | + T* params_; |
| 142 | +}; |
| 143 | + |
110 | 144 | }
|
111 | 145 |
|
112 | 146 | static AppWindow* getAppWindow(UIThreadExtensionFunction* func) {
|
@@ -622,9 +656,25 @@ bool NwCurrentWindowInternalIsKioskInternalFunction::RunNWSync(base::ListValue*
|
622 | 656 | return true;
|
623 | 657 | }
|
624 | 658 |
|
625 |
| -bool NwCurrentWindowInternalGetTitleInternalFunction::RunNWSync(base::ListValue* response, std::string* error) { |
| 659 | +bool NwCurrentWindowInternalGetTitleInternalFunction::RunNWSync(base::ListValue* response, std::string* ret_error) { |
626 | 660 | AppWindow* window = getAppWindow(this);
|
627 |
| - response->AppendString(window->title_override()); |
| 661 | + if (window) { |
| 662 | + response->AppendString(window->title_override()); |
| 663 | + return true; |
| 664 | + } |
| 665 | + Browser* browser = nullptr; |
| 666 | + std::string error; |
| 667 | + if (!windows_util::GetBrowserFromWindowID( |
| 668 | + this, extension_misc::kCurrentWindowId, WindowController::GetAllWindowFilter(), |
| 669 | + &browser, &error)) { |
| 670 | + *ret_error = error; |
| 671 | + return false; |
| 672 | + } |
| 673 | + if (!browser) { |
| 674 | + *ret_error = "no window found"; |
| 675 | + return false; |
| 676 | + } |
| 677 | + response->AppendString(browser->GetWindowTitleForCurrentTab(false)); |
628 | 678 | return true;
|
629 | 679 | }
|
630 | 680 |
|
|
0 commit comments