2
* Copyright 2010 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: gagansingh@google.com (Gagan Singh)
19
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_JS_DISABLE_FILTER_H_
20
#define NET_INSTAWEB_REWRITER_PUBLIC_JS_DISABLE_FILTER_H_
22
#include "net/instaweb/http/public/user_agent_matcher.h"
23
#include "net/instaweb/rewriter/public/common_filter.h"
24
#include "net/instaweb/rewriter/public/script_tag_scanner.h"
25
#include "net/instaweb/util/public/basictypes.h"
26
#include "net/instaweb/util/public/string.h"
28
namespace net_instaweb {
33
// Disables javscript by converting input html:
34
// <script src="1.js">var a = 1...</script>
36
// <noscript disabled="true">
37
// <script src="1.js">var a = 1...</script>
40
class JsDisableFilter : public CommonFilter {
42
explicit JsDisableFilter(RewriteDriver* driver);
45
static const char kEnableJsExperimental[];
46
static const char kElementOnloadCode[];
48
virtual void DetermineEnabled(GoogleString* disabled_reason);
50
virtual const char* Name() const {
51
return "JsDisableFilter";
55
virtual void StartDocumentImpl();
57
virtual void StartElementImpl(HtmlElement* element);
59
virtual void EndElementImpl(HtmlElement* element);
61
virtual void EndDocument();
63
// Inserts the experimental js enable/disable code.
64
void InsertJsDeferExperimentalScript();
66
// Insert meta tag with 'X-UA-Compatible'. This will avoid IE going to quirks
67
// mode. More information about this can be found in
68
// http://webdesign.about.com/od/metataglibraries/p/x-ua-compatible-meta-tag.htm
69
void InsertMetaTagForIE(HtmlElement* element);
71
ScriptTagScanner script_tag_scanner_;
73
bool ie_meta_tag_written_;
74
int prefetch_js_elements_count_;
75
int max_prefetch_js_elements_;
76
GoogleString prefetch_js_elements_;
77
bool should_look_for_prefetch_js_elements_;
78
UserAgentMatcher::PrefetchMechanism prefetch_mechanism_;
80
DISALLOW_COPY_AND_ASSIGN(JsDisableFilter);
83
} // namespace net_instaweb
85
#endif // NET_INSTAWEB_REWRITER_PUBLIC_JS_DISABLE_FILTER_H_