Skip to content

Commit b0c1be2

Browse files
committed
Merge branch 'nw21' of https://github.com/nwjs/chromium.src into nw21
2 parents 319d6c0 + 1e188d1 commit b0c1be2

File tree

11 files changed

+181
-22
lines changed

11 files changed

+181
-22
lines changed

base/native_library_win.cc

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,88 @@
77
#include <windows.h>
88

99
#include "base/files/file_util.h"
10+
#include "base/path_service.h"
1011
#include "base/strings/string_util.h"
1112
#include "base/strings/stringprintf.h"
1213
#include "base/strings/utf_string_conversions.h"
1314
#include "base/threading/thread_restrictions.h"
15+
#include "base/win/iat_patch_function.h"
16+
#include "chrome/common/chrome_paths.h"
1417

1518
namespace base {
1619

1720
typedef HMODULE (WINAPI* LoadLibraryFunction)(const wchar_t* file_name);
1821

1922
namespace {
2023

24+
base::win::IATPatchFunction* FlashCreateProcessProxy = nullptr;
25+
26+
BOOL WINAPI CreateProcessAForFlash(
27+
_In_opt_ LPCSTR lpApplicationName,
28+
_Inout_opt_ LPSTR lpCommandLine,
29+
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
30+
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
31+
_In_ BOOL bInheritHandles,
32+
_In_ DWORD dwCreationFlags,
33+
_In_opt_ LPVOID lpEnvironment,
34+
_In_opt_ LPCSTR lpCurrentDirectory,
35+
_In_ LPSTARTUPINFOA lpStartupInfo,
36+
_Out_ LPPROCESS_INFORMATION lpProcessInformation) {
37+
bool unhook = false;
38+
if (FlashCreateProcessProxy != nullptr &&
39+
strstr(lpCommandLine, "cmd.exe /c echo NOT SANDBOXED") != NULL) {
40+
unhook = true;
41+
dwCreationFlags |= CREATE_NO_WINDOW;
42+
}
43+
44+
typedef BOOL(WINAPI *CREATE_PROC) (
45+
LPCSTR,
46+
LPSTR,
47+
LPSECURITY_ATTRIBUTES,
48+
LPSECURITY_ATTRIBUTES,
49+
BOOL,
50+
DWORD,
51+
LPVOID,
52+
LPCSTR,
53+
LPSTARTUPINFOA,
54+
LPPROCESS_INFORMATION
55+
);
56+
57+
if (FlashCreateProcessProxy != nullptr) {
58+
CREATE_PROC createProc = (CREATE_PROC)FlashCreateProcessProxy->original_function();
59+
BOOL retVal = createProc(
60+
lpApplicationName,
61+
lpCommandLine,
62+
lpProcessAttributes,
63+
lpThreadAttributes,
64+
bInheritHandles,
65+
dwCreationFlags,
66+
lpEnvironment,
67+
lpCurrentDirectory,
68+
lpStartupInfo,
69+
lpProcessInformation
70+
);
71+
72+
if (unhook) {
73+
DWORD lastError = GetLastError();
74+
delete FlashCreateProcessProxy;
75+
FlashCreateProcessProxy = nullptr;
76+
SetLastError(lastError);
77+
}
78+
return retVal;
79+
}
80+
return FALSE;
81+
}
82+
83+
bool IsFlash(const FilePath& library_path) {
84+
base::FilePath flash_filename;
85+
if (!PathService::Get(chrome::FILE_PEPPER_FLASH_SYSTEM_PLUGIN,
86+
&flash_filename))
87+
return false;
88+
89+
return flash_filename == library_path;
90+
}
91+
2192
NativeLibrary LoadNativeLibraryHelper(const FilePath& library_path,
2293
LoadLibraryFunction load_library_api,
2394
NativeLibraryLoadError* error) {
@@ -42,6 +113,20 @@ NativeLibrary LoadNativeLibraryHelper(const FilePath& library_path,
42113
error->code = GetLastError();
43114
}
44115

116+
if (module) {
117+
if (IsFlash(library_path)) {
118+
FlashCreateProcessProxy = new base::win::IATPatchFunction;
119+
if (NO_ERROR !=
120+
FlashCreateProcessProxy->Patch(library_path.value().c_str(),
121+
"kernel32.dll",
122+
"CreateProcessA",
123+
CreateProcessAForFlash)) {
124+
delete FlashCreateProcessProxy;
125+
FlashCreateProcessProxy = nullptr;
126+
}
127+
}
128+
}
129+
45130
if (restore_directory)
46131
SetCurrentDirectory(current_directory);
47132

chrome/browser/download/download_ui_controller.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include "content/public/browser/download_item.h"
1919
#include "content/public/browser/web_contents.h"
2020
#include "content/public/browser/web_contents_delegate.h"
21+
#include "extensions/browser/app_window/app_window.h"
22+
#include "extensions/browser/app_window/app_window_registry.h"
23+
#include "extensions/browser/app_window/native_app_window.h"
2124

2225
#if defined(OS_ANDROID)
2326
#include "chrome/browser/android/download/download_controller_base.h"
@@ -159,6 +162,20 @@ void DownloadUIController::OnDownloadUpdated(content::DownloadManager* manager,
159162
#if !defined(OS_ANDROID)
160163
content::WebContents* web_contents = item->GetWebContents();
161164
if (web_contents) {
165+
Profile* profile = Profile::FromBrowserContext(web_contents->GetBrowserContext());
166+
extensions::AppWindowRegistry* registry = extensions::AppWindowRegistry::Get(profile);
167+
if (!registry)
168+
return;
169+
extensions::AppWindow* app_window = registry->GetAppWindowForWebContents(web_contents);
170+
if (!app_window)
171+
return;
172+
if (web_contents->GetController().IsInitialNavigation() &&
173+
app_window->NWCanClose() &&
174+
!item->IsSavePackageDownload()) {
175+
app_window->GetBaseWindow()->Close();
176+
}
177+
178+
#if 0
162179
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
163180
// If the download occurs in a new tab, and it's not a save page
164181
// download (started before initial navigation completed) close it.
@@ -172,6 +189,7 @@ void DownloadUIController::OnDownloadUpdated(content::DownloadManager* manager,
172189
!item->IsSavePackageDownload()) {
173190
web_contents->Close();
174191
}
192+
#endif
175193
}
176194
#endif
177195

chrome/browser/ui/chrome_bubble_manager.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,15 @@ static void LogBubbleCloseReason(BubbleReference bubble,
111111
ChromeBubbleManager::ChromeBubbleManager(TabStripModel* tab_strip_model)
112112
: tab_strip_model_(tab_strip_model) {
113113
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
114-
DCHECK(tab_strip_model_);
115-
tab_strip_model_->AddObserver(this);
114+
//DCHECK(tab_strip_model_);
115+
if (tab_strip_model_)
116+
tab_strip_model_->AddObserver(this);
116117
AddBubbleManagerObserver(&chrome_bubble_metrics_);
117118
}
118119

119120
ChromeBubbleManager::~ChromeBubbleManager() {
120-
tab_strip_model_->RemoveObserver(this);
121+
if (tab_strip_model_)
122+
tab_strip_model_->RemoveObserver(this);
121123

122124
// Finalize requests before removing the BubbleManagerObserver so it can
123125
// collect metrics when closing any open bubbles.

chrome/browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ class Browser;
1616
@class ChooserBubbleUiController;
1717
class ChooserController;
1818

19+
namespace extensions {
20+
class AppWindow;
21+
}
22+
1923
// ChooserBubbleUiCocoa implements a chooser-based permission model.
2024
// It uses |NSTableView| to show a list of options for user to grant
2125
// permission. It can be used by the WebUSB or WebBluetooth APIs.
2226
// It is owned by the BubbleController, which is owned by the BubbleManager.
2327
class ChooserBubbleUiCocoa : public BubbleUi {
2428
public:
2529
ChooserBubbleUiCocoa(Browser* browser,
30+
extensions::AppWindow* app_window,
2631
std::unique_ptr<ChooserController> chooser_controller);
2732
~ChooserBubbleUiCocoa() override;
2833

@@ -36,6 +41,7 @@ class ChooserBubbleUiCocoa : public BubbleUi {
3641

3742
private:
3843
Browser* browser_; // Weak.
44+
extensions::AppWindow* app_window_;
3945
// Cocoa-side chooser bubble UI controller. Weak, as it will close itself.
4046
ChooserBubbleUiController* chooser_bubble_ui_controller_;
4147

chrome/browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.mm

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#import "chrome/browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.h"
66

7+
#include "extensions/browser/app_window/app_window.h"
78
#include <stddef.h>
89

910
#include <algorithm>
@@ -29,7 +30,7 @@
2930
#include "ui/base/cocoa/window_size_constants.h"
3031

3132
std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
32-
return base::MakeUnique<ChooserBubbleUiCocoa>(browser_,
33+
return base::MakeUnique<ChooserBubbleUiCocoa>(browser_, app_window_,
3334
std::move(chooser_controller_));
3435
}
3536

@@ -47,10 +48,12 @@ @interface ChooserBubbleUiController
4748
NSButton* cancelButton_; // Weak.
4849

4950
Browser* browser_; // Weak.
51+
extensions::AppWindow* app_window_;
5052
}
5153

5254
// Designated initializer. |browser| and |bridge| must both be non-nil.
5355
- (id)initWithBrowser:(Browser*)browser
56+
appWindow:(extensions::AppWindow*)app_window
5457
chooserController:(std::unique_ptr<ChooserController>)chooserController
5558
bridge:(ChooserBubbleUiCocoa*)bridge;
5659

@@ -88,13 +91,15 @@ - (void)onCancel:(id)sender;
8891
@implementation ChooserBubbleUiController
8992

9093
- (id)initWithBrowser:(Browser*)browser
94+
appWindow:(extensions::AppWindow*)app_window
9195
chooserController:(std::unique_ptr<ChooserController>)chooserController
9296
bridge:(ChooserBubbleUiCocoa*)bridge {
93-
DCHECK(browser);
97+
//DCHECK(browser);
9498
DCHECK(chooserController);
9599
DCHECK(bridge);
96100

97101
browser_ = browser;
102+
app_window_ = app_window;
98103

99104
base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc]
100105
initWithContentRect:ui::kWindowSizeDeterminedLater
@@ -242,16 +247,20 @@ - (NSPoint)getExpectedAnchorPoint {
242247
}
243248

244249
- (bool)hasLocationBar {
245-
return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
250+
return false; //browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
246251
}
247252

248253
- (info_bubble::BubbleArrowLocation)getExpectedArrowLocation {
249254
return [self hasLocationBar] ? info_bubble::kTopLeft : info_bubble::kNoArrow;
250255
}
251256

252257
- (NSWindow*)getExpectedParentWindow {
253-
DCHECK(browser_->window());
254-
return browser_->window()->GetNativeWindow();
258+
if (browser_) {
259+
DCHECK(browser_->window());
260+
return browser_->window()->GetNativeWindow();
261+
} else {
262+
return app_window_->GetNativeWindow();
263+
}
255264
}
256265

257266
+ (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB {
@@ -291,13 +300,16 @@ - (void)onCancel:(id)sender {
291300

292301
ChooserBubbleUiCocoa::ChooserBubbleUiCocoa(
293302
Browser* browser,
303+
extensions::AppWindow* app_window,
294304
std::unique_ptr<ChooserController> chooser_controller)
295305
: browser_(browser),
306+
app_window_(app_window),
296307
chooser_bubble_ui_controller_(nil) {
297-
DCHECK(browser_);
308+
//DCHECK(browser_);
298309
DCHECK(chooser_controller);
299310
chooser_bubble_ui_controller_ = [[ChooserBubbleUiController alloc]
300311
initWithBrowser:browser_
312+
appWindow:app_window_
301313
chooserController:std::move(chooser_controller)
302314
bridge:this];
303315
}

chrome/browser/ui/views/website_settings/chooser_bubble_ui_view.cc

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "chrome/browser/ui/views/website_settings/chooser_bubble_ui_view.h"
66

7+
#include "extensions/components/native_app_window/native_app_window_views.h"
78
#include <stddef.h>
89

910
#include <memory>
@@ -29,7 +30,7 @@
2930
#include "ui/views/window/dialog_client_view.h"
3031

3132
std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
32-
return base::MakeUnique<ChooserBubbleUiView>(browser_,
33+
return base::MakeUnique<ChooserBubbleUiView>(browser_, app_window_,
3334
std::move(chooser_controller_));
3435
}
3536

@@ -184,12 +185,13 @@ void ChooserBubbleUiViewDelegate::UpdateTableView() const {
184185
// ChooserBubbleUiView
185186
ChooserBubbleUiView::ChooserBubbleUiView(
186187
Browser* browser,
188+
void* app_window,
187189
std::unique_ptr<ChooserController> chooser_controller)
188-
: browser_(browser), chooser_bubble_ui_view_delegate_(nullptr) {
189-
DCHECK(browser_);
190+
: browser_(browser), app_window_((extensions::AppWindow*)app_window), chooser_bubble_ui_view_delegate_(nullptr) {
191+
//DCHECK(browser_);
190192
DCHECK(chooser_controller);
191193
chooser_bubble_ui_view_delegate_ = new ChooserBubbleUiViewDelegate(
192-
GetAnchorView(), GetAnchorArrow(), std::move(chooser_controller));
194+
nullptr, GetAnchorArrow(), std::move(chooser_controller));
193195
}
194196

195197
ChooserBubbleUiView::~ChooserBubbleUiView() {}
@@ -198,10 +200,11 @@ void ChooserBubbleUiView::Show(BubbleReference bubble_reference) {
198200
chooser_bubble_ui_view_delegate_->set_bubble_reference(bubble_reference);
199201

200202
// Set |parent_window| because some valid anchors can become hidden.
201-
views::Widget* widget = views::Widget::GetWidgetForNativeWindow(
202-
browser_->window()->GetNativeWindow());
203-
chooser_bubble_ui_view_delegate_->set_parent_window(widget->GetNativeView());
204-
203+
views::Widget* widget = nullptr;
204+
if (browser_) {
205+
widget = views::Widget::GetWidgetForNativeWindow(browser_->window()->GetNativeWindow());
206+
chooser_bubble_ui_view_delegate_->set_parent_window(widget->GetNativeView());
207+
}
205208
views::BubbleDialogDelegateView::CreateBubble(
206209
chooser_bubble_ui_view_delegate_)
207210
->Show();
@@ -217,6 +220,7 @@ void ChooserBubbleUiView::UpdateAnchorPosition() {
217220
}
218221

219222
views::View* ChooserBubbleUiView::GetAnchorView() {
223+
if (browser_) {
220224
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_);
221225

222226
if (browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR))
@@ -228,10 +232,16 @@ views::View* ChooserBubbleUiView::GetAnchorView() {
228232
return browser_view->exclusive_access_bubble()->GetView();
229233

230234
return browser_view->top_container();
235+
} else if (app_window_) {
236+
native_app_window::NativeAppWindowViews* native_app_window_views =
237+
static_cast<native_app_window::NativeAppWindowViews*>(app_window_->GetBaseWindow());
238+
return native_app_window_views->web_view();
239+
}
240+
return nullptr;
231241
}
232242

233243
views::BubbleBorder::Arrow ChooserBubbleUiView::GetAnchorArrow() {
234-
if (browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR))
244+
if (browser_ && browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR))
235245
return views::BubbleBorder::TOP_LEFT;
236246
return views::BubbleBorder::NONE;
237247
}

chrome/browser/ui/views/website_settings/chooser_bubble_ui_view.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ namespace views {
1515
class View;
1616
}
1717

18+
namespace extensions {
19+
class AppWindow;
20+
}
21+
1822
class Browser;
1923
class ChooserController;
2024
class ChooserBubbleUiViewDelegate;
@@ -26,7 +30,7 @@ class ChooserBubbleUiViewDelegate;
2630
// BubbleManager.
2731
class ChooserBubbleUiView : public BubbleUi {
2832
public:
29-
ChooserBubbleUiView(Browser* browser,
33+
ChooserBubbleUiView(Browser* browser, void* app_window,
3034
std::unique_ptr<ChooserController> chooser_controller);
3135
~ChooserBubbleUiView() override;
3236

@@ -40,6 +44,7 @@ class ChooserBubbleUiView : public BubbleUi {
4044
views::BubbleBorder::Arrow GetAnchorArrow();
4145

4246
Browser* browser_; // Weak.
47+
extensions::AppWindow* app_window_;
4348
// Weak. Owned by its parent view.
4449
ChooserBubbleUiViewDelegate* chooser_bubble_ui_view_delegate_;
4550

0 commit comments

Comments
 (0)