1 // Copyright 2013 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.
5 #include "chrome/browser/guestview/adview/adview_guest.h"
7 #include "base/strings/string_util.h"
8 #include "chrome/browser/guestview/adview/adview_constants.h"
9 #include "chrome/browser/guestview/guestview_constants.h"
10 #include "content/public/browser/web_contents.h"
11 #include "net/base/net_errors.h"
13 using content::WebContents
;
15 AdViewGuest::AdViewGuest(WebContents
* guest_web_contents
,
16 const std::string
& extension_id
)
17 : GuestView(guest_web_contents
, extension_id
),
18 WebContentsObserver(guest_web_contents
) {
22 AdViewGuest
* AdViewGuest::From(int embedder_process_id
,
23 int guest_instance_id
) {
24 GuestView
* guest
= GuestView::From(embedder_process_id
, guest_instance_id
);
27 return guest
->AsAdView();
30 GuestView::Type
AdViewGuest::GetViewType() const {
31 return GuestView::ADVIEW
;
34 WebViewGuest
* AdViewGuest::AsWebView() {
38 AdViewGuest
* AdViewGuest::AsAdView() {
42 AdViewGuest::~AdViewGuest() {
45 void AdViewGuest::DidCommitProvisionalLoadForFrame(
47 const base::string16
& frame_unique_name
,
50 content::PageTransition transition_type
,
51 content::RenderViewHost
* render_view_host
) {
52 scoped_ptr
<base::DictionaryValue
> args(new base::DictionaryValue());
53 args
->SetString(guestview::kUrl
, url
.spec());
54 args
->SetBoolean(guestview::kIsTopLevel
, is_main_frame
);
55 DispatchEvent(new GuestView::Event(adview::kEventLoadCommit
, args
.Pass()));
58 void AdViewGuest::DidFailProvisionalLoad(
60 const base::string16
& frame_unique_name
,
62 const GURL
& validated_url
,
64 const base::string16
& error_description
,
65 content::RenderViewHost
* render_view_host
) {
66 // Translate the |error_code| into an error string.
67 std::string error_type
;
68 base::RemoveChars(net::ErrorToString(error_code
), "net::", &error_type
);
70 scoped_ptr
<base::DictionaryValue
> args(new base::DictionaryValue());
71 args
->SetBoolean(guestview::kIsTopLevel
, is_main_frame
);
72 args
->SetString(guestview::kUrl
, validated_url
.spec());
73 args
->SetString(guestview::kReason
, error_type
);
74 DispatchEvent(new GuestView::Event(adview::kEventLoadAbort
, args
.Pass()));