forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve the beforeinstallprompt event's promise.
This resolves the promise sent with the beforeinstallprompt banner, after the banner is shown and either dismissed or accepted. BUG=460945 Review URL: https://codereview.chromium.org/1120543002 Cr-Commit-Position: refs/heads/master@{#328505}
- Loading branch information
benwells
authored and
Commit bot
committed
May 6, 2015
1 parent
4fb7be4
commit 04ab5b9
Showing
17 changed files
with
202 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/renderer/banners/app_banner_client.h" | ||
|
||
#include "chrome/common/render_messages.h" | ||
#include "ipc/ipc_message.h" | ||
#include "third_party/WebKit/public/platform/WebString.h" | ||
|
||
using blink::WebString; | ||
|
||
AppBannerClient::AppBannerClient(content::RenderFrame* render_frame) | ||
: content::RenderFrameObserver(render_frame) { | ||
} | ||
|
||
AppBannerClient::~AppBannerClient() { | ||
} | ||
|
||
bool AppBannerClient::OnMessageReceived(const IPC::Message& message) { | ||
bool handled = true; | ||
IPC_BEGIN_MESSAGE_MAP(AppBannerClient, message) | ||
IPC_MESSAGE_HANDLER(ChromeViewMsg_AppBannerAccepted, OnBannerAccepted); | ||
IPC_MESSAGE_HANDLER(ChromeViewMsg_AppBannerDismissed, OnBannerDismissed); | ||
IPC_MESSAGE_UNHANDLED(handled = false) | ||
IPC_END_MESSAGE_MAP() | ||
return handled; | ||
} | ||
|
||
void AppBannerClient::registerBannerCallbacks( | ||
int request_id, | ||
blink::WebAppBannerCallbacks* callbacks) { | ||
banner_callbacks_.AddWithID(callbacks, request_id); | ||
} | ||
|
||
void AppBannerClient::ResolveEvent( | ||
int request_id, | ||
const std::string& platform, | ||
const blink::WebAppBannerPromptResult::Outcome& outcome) { | ||
blink::WebAppBannerCallbacks* callbacks = | ||
banner_callbacks_.Lookup(request_id); | ||
if (!callbacks) | ||
return; | ||
|
||
scoped_ptr<blink::WebAppBannerPromptResult> result( | ||
new blink::WebAppBannerPromptResult( | ||
blink::WebString::fromUTF8(platform), | ||
outcome)); | ||
callbacks->onSuccess(result.release()); | ||
banner_callbacks_.Remove(request_id); | ||
} | ||
|
||
void AppBannerClient::OnBannerAccepted(int request_id, | ||
const std::string& platform) { | ||
ResolveEvent(request_id, platform, | ||
blink::WebAppBannerPromptResult::Outcome::Accepted); | ||
} | ||
|
||
void AppBannerClient::OnBannerDismissed(int request_id) { | ||
ResolveEvent(request_id, "", | ||
blink::WebAppBannerPromptResult::Outcome::Dismissed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_RENDERER_BANNERS_APP_BANNER_CLIENT_H_ | ||
#define CHROME_RENDERER_BANNERS_APP_BANNER_CLIENT_H_ | ||
|
||
#include <stdint.h> | ||
#include <string> | ||
|
||
#include "base/id_map.h" | ||
#include "content/public/renderer/render_frame_observer.h" | ||
#include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerClient.h" | ||
#include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerPromptResult.h" | ||
|
||
namespace IPC { | ||
class Message; | ||
} // namespace IPC | ||
|
||
class AppBannerClient : public content::RenderFrameObserver, | ||
public blink::WebAppBannerClient { | ||
public: | ||
explicit AppBannerClient(content::RenderFrame* render_frame); | ||
virtual ~AppBannerClient(); | ||
|
||
private: | ||
// content::RenderFrame::Observer implementation. | ||
bool OnMessageReceived(const IPC::Message& message) override; | ||
|
||
// WebAppBannerClient implementation. | ||
void registerBannerCallbacks(int request_id, | ||
blink::WebAppBannerCallbacks*) override; | ||
|
||
void ResolveEvent(int request_id, | ||
const std::string& platform, | ||
const blink::WebAppBannerPromptResult::Outcome& outcome); | ||
void OnBannerAccepted(int request_id, const std::string& platform); | ||
void OnBannerDismissed(int request_id); | ||
|
||
IDMap<blink::WebAppBannerCallbacks, IDMapOwnPointer> | ||
banner_callbacks_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(AppBannerClient); | ||
}; | ||
|
||
#endif // CHROME_RENDERER_BANNERS_APP_BANNER_CLIENT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.