2
* Copyright 2012 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Author: pulkitg@google.com (Pulkit Goyal)
19
// Contains the implementation of the DeferIframeFilter which defers the iframe
20
// using JsDeferDisabledJavascriptFilter. This filter should be called before
21
// JsDeferDisabledJavascriptFilter. This filter renames all the iframe tags to
22
// pagespeed_iframe and add a script which converts pagespeed_iframe back to
23
// iframe and the added script is deferred by JsDeferDisabledJavascriptFilter.
25
// Html input to this filter looks like:
30
// <iframe src="1.html"></iframe>
34
// Output for the above html will be:
40
// defer_iframe script.
42
// <pagespeed_iframe src="1.html">
44
// Script which changes above pagespeed_iframe tag name to iframe.
46
// </pagespeed_iframe>
50
// Above script which converts pagespeed_iframe to iframe will be deferred
51
// by JsDeferDisabledJavascriptFilter, hence loading of iframe is also deferred.
53
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_DEFER_IFRAME_FILTER_H_
54
#define NET_INSTAWEB_REWRITER_PUBLIC_DEFER_IFRAME_FILTER_H_
56
#include "net/instaweb/rewriter/public/common_filter.h"
57
#include "net/instaweb/util/public/basictypes.h"
59
namespace net_instaweb {
63
class StaticAssetManager;
65
class DeferIframeFilter : public CommonFilter {
67
static const char kDeferIframeInit[];
68
static const char kDeferIframeIframeJs[];
69
explicit DeferIframeFilter(RewriteDriver* driver);
72
virtual void StartDocumentImpl();
73
virtual void StartElementImpl(HtmlElement* element);
74
virtual void EndElementImpl(HtmlElement* element);
75
virtual void DetermineEnabled(GoogleString* disabled_reason);
77
virtual const char* Name() const { return "DeferIframe"; }
80
StaticAssetManager* static_asset_manager_;
81
bool script_inserted_;
83
DISALLOW_COPY_AND_ASSIGN(DeferIframeFilter);
86
} // namespace net_instaweb
88
#endif // NET_INSTAWEB_REWRITER_PUBLIC_DEFER_IFRAME_FILTER_H_